#Q135. 「一本通 4.4 例 4」次小生成树
「一本通 4.4 例 4」次小生成树
Description
Original source: BeiJing 2010 Team Competition
Given an undirected graph with vertices and edges, find the strictly second-minimum spanning tree.
Let the sum of edge weights in the minimum spanning tree be . The strictly second-minimum spanning tree is the one with the smallest edge weight sum among all spanning trees whose edge weight sums are greater than .
Input Format
The first line contains two integers and , representing the number of vertices and edges in the undirected graph, respectively.
The next lines each contain three integers , , and , indicating an edge between vertex and vertex with a weight of .
Output Format
Output a single line containing only one number, which is the edge weight sum of the strictly second-minimum spanning tree.
It is guaranteed that the strictly second-minimum spanning tree exists.
Sample 1
5 6
1 2 1
1 3 2
2 4 3
3 5 4
3 4 3
4 5 6
11
Data Range and Hints
For all data, , . The undirected graph contains no self-loops, and edge weights are non-negative and do not exceed .