#P4180. [BJWC2010] 严格次小生成树
[BJWC2010] 严格次小生成树
Description
Xiao C recently learned many algorithms for the minimum spanning tree, such as Prim, Kruskal, and cycle-canceling, etc. Just as Xiao C was feeling proud, Xiao P poured cold water on him. Xiao P asked Xiao C to find the second minimum spanning tree of an undirected graph, and it must be strictly second, that is: if the edge set chosen by the minimum spanning tree is , and the edge set chosen by the strictly second minimum spanning tree is , then it must satisfy: (here denotes the weight of edge ) .
Xiao C was stumped and came to you for help to solve this problem.
Input Format
The first line contains two integers and , denoting the number of vertices and edges of the undirected graph.
The next lines each contain three numbers , indicating that there is an edge between vertex and vertex with weight .
Output Format
Output one line with a single number, the sum of edge weights of the strictly second minimum spanning tree.
5 6
1 2 1
1 3 2
2 4 3
3 5 4
3 4 3
4 5 6
11
Hint
- The undirected graph may contain self-loops.
Constraints:
- For 50% of the testdata, , .
- For 80% of the testdata, , .
- For 100% of the testdata, , , edge weights , and the testdata guarantees that a strictly second minimum spanning tree exists.
Translated by ChatGPT 5
京公网安备 11011102002149号