#C11195. Longest Path in a Weighted Tree

    ID: 40484 Type: Default 1000ms 256MiB

Longest Path in a Weighted Tree

Longest Path in a Weighted Tree

You are given a tree with n nodes and n-1 edges. Each edge has an integer weight associated with it. Your task is to determine the length of the longest path in the tree (also known as the diameter of the tree).

The diameter of a tree is defined as the maximum sum of weights on the path between any two nodes in the tree. Formally, if there exists a path between nodes u and v with weights w1, w2, ..., wk, then the path length is given by:

length=i=1kwi\text{length} = \sum_{i=1}^{k} w_i

Your solution should read the input from standard input (stdin) and print the result to standard output (stdout).

inputFormat

The first line of the input contains a single integer n (2 ≤ n ≤ 105), representing the number of nodes in the tree.

The following n-1 lines each contain three space-separated integers u, v and w (1 ≤ u, v ≤ n, 1 ≤ w ≤ 104), representing an edge between nodes u and v with weight w.

outputFormat

Output a single integer denoting the length of the longest path in the tree.

## sample
5
1 2 3
2 3 4
3 4 2
4 5 6
15

</p>