← 返回 citadel 的题目列表Tree Diameter
类型:online_judge
Problem: Tree Diameter
Given an undirected tree with n nodes labeled from 0 to n - 1 and n - 1 undirected edges.
Return the diameter length of the tree. The diameter is defined as the maximum number of edges on the shortest path between any two nodes in the tree.
Input Format
The first line contains an integer n.
The next n - 1 lines each contain two integers u v, representing an undirected edge between nodes u and v.
Output Format
Print one integer, the diameter length of the tree.
Constraints
1 <= n <= 2 * 10^5
0 <= u, v < n
The input is guaranteed to form a tree
Example
Input:
5
0 1
1 2
1 3
3 4
Output:
3
Example
Input
1
Output
0