Diameter of a Tree
A tree has nodes and edges. Its diameter is the number of edges on the longest path between any two nodes. Find it. (Trick: BFS from any node to the farthest node , then BFS from .)
Input
, then lines u v.
Output
The diameter.
Constraints
Sample 1
Input
5 1 2 1 3 3 4 3 5
Output
3