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

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

1 lộ trình

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 nn vertices with unit-length edges, every pair of vertices has a unique simple connecting path.

For each vertex uu, find the maximum number of edges on the path from uu to any vertex vv. The choice v=uv=u is allowed, giving distance 00.

Input

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

Output

Print nn integers; the uu-th integer is the maximum distance from vertex uu.

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

2 3 2 3 3

Explanation

From vertex 22, vertices 44 and 55 are three edges away. The largest distance from vertex 11 is two; the answers are 2,3,2,3,32,3,2,3,3.