PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#LCA0000003. Đường kính của cây (Tree Diameter)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Đường kính của cây (Tree Diameter)

Tree Diameter

Source: CSES

Version: Phuoc Hung OJ Extended

Problem Statement

An undirected tree has nn vertices and n−1n-1 edges. Every edge has length 11.

The distance between two vertices is the number of edges on the unique simple path connecting them. The diameter is the greatest distance over all pairs of vertices.

Determine the tree diameter.

Input

  • The first line contains nn.
  • Each of the next n−1n-1 lines contains an undirected edge ai,bia_i,b_i.

Output

Print one integer: the diameter length.

Subtasks

  • Subtask 1 (20 points): n≤30n\le30; 1≤n≤2⋅1051\le n\le2\cdot10^5.
  • Subtask 2 (30 points): n≤1000n\le1000; 1≤n≤2⋅1051\le n\le2\cdot10^5.
  • Subtask 3 (50 points): 1≤n≤2⋅1051\le n\le2\cdot10^5.

Examples

Input

5
1 2
1 3
3 4
3 5

Output

3

Explanation

The path 2o1o3o42 o1 o3 o4 uses three edges and is a longest path; hence the diameter equals 33.