#Q135. 「一本通 4.4 例 4」次小生成树

「一本通 4.4 例 4」次小生成树

Description

Original source: BeiJing 2010 Team Competition

Given an undirected graph with NN vertices and MM edges, find the strictly second-minimum spanning tree.

Let the sum of edge weights in the minimum spanning tree be sum\text{sum}. 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 sum\text{sum}.

Input Format

The first line contains two integers NN and MM, representing the number of vertices and edges in the undirected graph, respectively.

The next MM lines each contain three integers xx, yy, and zz, indicating an edge between vertex xx and vertex yy with a weight of zz.

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, 1N1051\le N\le 10^5, 1M3×1051\le M\le 3\times 10^5. The undirected graph contains no self-loops, and edge weights are non-negative and do not exceed 10910^9.