Longest path in a tree#10050

Longest path in a tree

2 seconds
128 megabytes
Very easy

An undirected weighted tree is given. Find the length of the longest simple path in the tree; that is, find two vertices such that the distance between them is maximized.

Input

The first line contains the number of vertices in the tree (2 \le n \le 10^5).

Each of the following n - 1 lines describes an edge of the tree. Each line contains three integers , , and , where and are the numbers of the vertices connected by the edge (vertices are numbered from to ), and (1 \le w \le 10^5) is the weight of the edge.

Output

Print the length of the longest path in the tree.

Examples

Example 1

Loading
Loading