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
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Đường kính của cây (Tree Diameter)
Tree Diameter
Source: CSES
Version: Phuoc Hung OJ Extended
Problem Statement
An undirected tree has vertices and edges. Every edge has length .
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 .
- Each of the next lines contains an undirected edge .
Output
Print one integer: the diameter length.
Subtasks
- Subtask 1 (20 points): ; .
- Subtask 2 (30 points): ; .
- Subtask 3 (50 points): .
Examples
Input
5
1 2
1 3
3 4
3 5
Output
3
Explanation
The path uses three edges and is a longest path; hence the diameter equals .