Time limit
2s
Memory limit
256 MB
In a tree, the distance between two vertices is the sum of the edge weights on the unique path connecting them. The diameter of a tree is the maximum distance over all pairs of vertices. Given a weighted tree, compute its diameter.
The first line contains the number of vertices V (2 <= V <= 100000). The vertices are numbered from 1 to V.
The next V lines describe the edges adjacent to each vertex. Each line starts with a vertex number, followed by zero or more pairs neighbor distance. The line ends with -1. Every distance is a positive integer no greater than 10000.
Print the diameter of the tree.