PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#FW0000102. Những con đường chạy bộ (Jogging Trails)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Những con đường chạy bộ (Jogging Trails)
Jogging Trails
Source: LightOJ
Version: Phuoc Hung OJ Extended
Problem Statement
Given an undirected graph with positive edge weights, find the minimum length of a closed walk covering every edge at least once. The starting vertex may be chosen anywhere within the active component. Output -1 if the graph edges do not all lie in a single connected component.
Input
First , then roads indexed from .
Output
Print the minimum tour 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
The graph has one edge of length 3. A closed walk covering it traverses the edge in both directions, yielding .