CF BUDDY
← Problems·

1805D · A Wide, Wide Graph

1800 · dfs and similar, dp, graphs

Problem: You are given a tree (a connected graph without cycles) with nn vertices.

Consider a fixed integer kk. Then, the graph GkG_k is an undirected graph with nn vertices, where an edge between vertices uu and vv exists if and only if the distance between vertices uu and vv in the given tree is at least kk.

For each kk from 11 to nn, print the number of connected components in the graph GkG_k.

Input Format: The first line contains the integer nn (2n1052 \le n \le 10^5) — the number of vertices in the graph.

Each of the next n1n-1 lines contains two integers uu and vv (1u,vn1 \le u, v \le n), denoting an edge between vertices uu and vv in the tree. It is guaranteed that these edges form a valid tree.

Output Format: Output nn integers: the number of connected components in the graph GkG_k for each kk from 11 to nn.

Note: In the first example: If k=1k=1, the graph has an edge between each pair of vertices, so it has one component. If k=4k=4, the graph has only edges 464 \leftrightarrow 6 and 565 \leftrightarrow 6, so the graph has 44 components.

In the second example: when k=1k=1 or k=2k=2 the graph has one component. When k=3k=3 the graph GkG_k splits into 33 components: one component has vertices 11, 44 and 55, and two more components contain one vertex each. When k=4k=4 or k=5k=5 each vertex is a separate component.

Sample Cases

Case 1

Input

6
1 2
1 3
2 4
2 5
3 6

Output

1 1 2 4 6 6

Case 2

Input

5
1 2
2 3
3 4
3 5

Output

1 1 3 5 5

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback