Skip to content
UPEEC

Diameter of a Tree

Hard#trees#bfs#dfs· solved by 0 · time limit 2.0 s

A tree has nn nodes and n−1n-1 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 aa, then BFS from aa.)

Input

nn, then n−1n-1 lines u v.

Output

The diameter.

Constraints

1≤n≤1051 \le n \le 10^5

Sample 1

Input

5
1 2
1 3
3 4
3 5

Output

3

Sign in or join free to run and submit your solution.