#abc361e. E - Tree and Hamilton Path 2

E - Tree and Hamilton Path 2

Score : 500500 points

问题陈述

在AtCoder国,有NN个城市,编号从11NN,以及N1N-1条道路,编号从11N1N-1

道路ii双向连接城市AiA_iBiB_i,其长度为CiC_i。任何一对城市都可以通过一些道路相互到达。

找出从某个城市出发,至少访问所有城市一次,使用道路所需的最小旅行距离。

以上为大语言模型 kimi 翻译,仅供参考。

Problem Statement

In the nation of AtCoder, there are NN cities numbered 11 to NN and N1N-1 roads numbered 11 to N1N-1.

Road ii connects cities AiA_i and BiB_i bidirectionally, and its length is CiC_i. Any pair of cities can be reached from each other by traveling through some roads.

Find the minimum travel distance required to start from a city and visit all cities at least once using the roads.

Constraints

  • 2N2×1052 \leq N \leq 2\times 10^5
  • 1Ai,BiN1 \leq A_i, B_i \leq N
  • 1Ci1091 \leq C_i \leq 10^9
  • All input values are integers.
  • Any pair of cities can be reached from each other by traveling through some roads.

Input

The input is given from Standard Input in the following format:

NN

A1A_1 B1B_1 C1C_1

\vdots

AN1A_{N-1} BN1B_{N-1} CN1C_{N-1}

Output

Print the answer.

Sample Input 1

4
1 2 2
1 3 3
1 4 4

Sample Output 1

11

If you travel as 412134 \to 1 \to 2 \to 1 \to 3, the total travel distance is 1111, which is the minimum.

Note that you do not need to return to the starting city.

Sample Input 2

10
10 9 1000000000
9 8 1000000000
8 7 1000000000
7 6 1000000000
6 5 1000000000
5 4 1000000000
4 3 1000000000
3 2 1000000000
2 1 1000000000

Sample Output 2

9000000000

Beware overflow.