Longest Corridor Walk
A museum has n rooms numbered from 1 to n, connected by n − 1 corridors. Each corridor joins two different rooms and has a length. You can get from any room to any other room through the corridors.
A night guard wants to plan the longest possible patrol. The guard starts in some room, walks through corridors and stops in some room, and never walks through the same corridor twice. The length of the patrol is the total length of the corridors walked.
Find the length of the longest possible patrol.
Input
The first line contains one integer n (1 ≤ n ≤ 2·10^5), the number of rooms.
Each of the next n − 1 lines contains three integers u, v, w (1 ≤ u, v ≤ n, u ≠ v, 1 ≤ w ≤ 10^9): a corridor of length w between rooms u and v.
You can get from any room to any other room through the corridors.
Output
Print one integer: the length of the longest patrol. If there is only one room, print 0.
Notes
In the first example, the longest patrol goes 3 → 2 → 4 → 5 and has length 4 + 2 + 6 = 12.
In the second example, the longest patrol goes 2 → 1 → 4 and has length 10 + 7 = 17.
The answer may not fit in a 32-bit integer.