PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#LCA0000004. Khoảng cách xa nhất từ mỗi đỉnh (Tree Distances I)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Khoảng cách xa nhất từ mỗi đỉnh (Tree Distances I)
Tree Distances I
Source: CSES
Version: Phuoc Hung OJ Extended
Problem Statement
Given an undirected tree of vertices with unit-length edges, every pair of vertices has a unique simple connecting path.
For each vertex , find the maximum number of edges on the path from to any vertex . The choice is allowed, giving distance .
Input
- The first line contains .
- Each of the next lines contains an edge .
Output
Print integers; the -th integer is the maximum distance from vertex .
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
2 3 2 3 3
Explanation
From vertex , vertices and are three edges away. The largest distance from vertex is two; the answers are .