#K85347. Longest Round Trip
Longest Round Trip
Longest Round Trip
You are given a magical land consisting of n towns connected by n - 1 bidirectional roads forming a tree. Each road has an associated positive length. The goal is to determine the longest possible round trip distance a traveler can take. Essentially, you are to compute the diameter of the tree (i.e. the longest distance between any two towns) and then output twice this value.
Mathematically, if the diameter of the tree is \(d\), then the longest round trip distance is \(2 \times d\).
The input is given in the following format:
- The first line contains an integer n representing the number of towns.
- Each of the next n - 1 lines contains three space-separated integers u, v, and w indicating a road between towns u and v with length w.
Your task is to compute and output the longest possible round trip distance.
inputFormat
The input is read from standard input (stdin) and has the following format:
- The first line contains a single integer n — the number of towns.
- The next n - 1 lines each contain three space-separated integers u, v, and w describing a road between towns u and v with a length w.
outputFormat
Output a single integer representing the longest possible round trip distance from standard output (stdout).
## sample3
1 2 3
2 3 4
14