#Q69. 「一本通 3.1 练习 2」构造完全图

「一本通 3.1 练习 2」构造完全图

Description

For a complete graph GG, if there is exactly one minimum spanning tree TT, then the complete graph GG is said to be extended by the tree TT.

Given a tree TT, find the complete graph GG with the smallest sum of edge weights that can be extended by TT.

Input Format

The first line contains NN, the number of vertices in the tree TT;

The next N1N-1 lines each contain three integers Si,Ti,DiS_i, T_i, D_i; describing an edge (Si,Ti)(S_i, T_i) with weight DiD_i;

It is guaranteed that the input data forms a tree.

Output Format

Output only one number, representing the smallest sum of edge weights for the complete graph GG.

Sample 1

Add D(2,3)=2,D(3,4)=3,D(2,4)=3D(2, 3)=2, D(3, 4)=3, D(2, 4)=3 to achieve this.

4
1 2 1
1 3 1
1 4 2

12

Data Range and Hints

For 20%20\% of the data, N10N\le 10;
For 50%50\% of the data, N1000N\le 1000;
For 100%100\% of the data, N105,1Di105N\le 10^5, 1\le D_i\le 10^5.