#P6643. [CCO 2020] Mountains and Valleys
[CCO 2020] Mountains and Valleys
Description
There is an undirected graph with vertices and edges, and each edge has a weight. The graph has no multiple edges and no self-loops. The vertices are numbered starting from .
Exactly edges have weight . All other edges have weight and . Also, if we only consider the edges with weight , the whole graph forms a tree.
Now you need to traverse every vertex exactly once, while making the total weight of the edges you travel as small as possible.
Find the minimum possible total edge weight.
Reminder:
- You may go back and forth along an edge.
- You may choose any vertex to start from.
- You have only one person.
Input Format
The first line contains two integers .
The next lines each contain three integers , indicating that there is an edge between and with weight .
Output Format
Output the minimum total edge weight required to traverse every vertex exactly once.
9 10
0 1 1
0 2 1
0 3 1
1 4 1
2 5 1
2 6 1
3 7 1
3 8 1
2 4 5
6 7 3
11
Hint
Sample Explanation

An optimal path is , with total edge weight .
Subtasks
This problem uses bundled testdata.
- Subtask 1 ( points): , .
- Subtask 2 ( points): , .
- Subtask 3 ( points): , , and or .
- Subtask 4 ( points): , .
- Subtask 5 ( points): , .
- Subtask 6 ( points): , .
- Subtask 7 ( points): , .
- Subtask 8 ( points): No special restrictions.
For of the data, it is guaranteed that , , , and or .
Notes
This problem is translated from Canadian Computing Olympiad 2020 Day 1 T3 Mountains and Valleys。
Translated by ChatGPT 5
京公网安备 11011102002149号