#FW0000101. Đồ thị du hành (Traveling Graph)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Đồ thị du hành (Traveling Graph)
Traveling Graph
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Given a weighted undirected multigraph, possibly with parallel edges and self-loops, find the minimum length of a closed walk starting at vertex 1, traversing every edge at least once, and returning to vertex 1. Output -1 if no such walk exists. All original edge weights must contribute, including parallel edges.
Input
First , followed by edges , with 1-based indices.
Output
Print the minimum total length or -1.
Subtasks
-
Subtask 1 (40 points): . All input-format and graph conditions above apply.
-
Subtask 2 (60 points): . All input-format and graph conditions above apply.
Examples
Input
2 1
1 2 3
Output
6
Explanation
To start and finish at vertex 1 while covering the only edge, the walk must be . Both traversals cost 3, totaling .