Diameter of a Tree
Print the diameter of the tree: the number of edges on the longest path between any two nodes.
Input: the first line has N; each of the next N−1 lines has an edge u v.
Output: the diameter.
Constraints:
- 1 ≤ N ≤ 105
Sample Tests
Input 1
5 1 2 2 3 2 4 4 5
Output 1
3
Input 2
1
Output 2
0
Discussion (opens after you solve — no spoilers before)
No comments yet.