Longest path in a tree#631

Longest path in a tree

2 seconds
128 megabytes
Medium (≈1350)

An undirected weighted tree is given. Find the longest path in it: identify two vertices such that the distance between them is maximized.

Input

The first line contains the number of vertices in the tree n~(2 \le n \le 10^5). The following n - 1 lines describe the edges. Each line contains three integers: the numbers of the vertices connected by an edge (vertices are numbered from to ) and the weight w~(1 \le w \le 10^5) of the edge.

Output

Print the length of the longest path in the tree.

Examples

Example 1

Loading
Loading