Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!

~/algor $ cat problems/daraxt-qism-daraxtlar

Subtree sizes

Medium 1000 ms 128 MB 62%
Share

A tree with $n$ vertices and $n - 1$ edges, rooted at vertex $1$, is given. The vertices are numbered from $1$ to $n$. The subtree of a vertex $v$ is $v$ itself and all vertices whose path from the root passes through $v$. For every vertex find the number of vertices in its subtree.

A rooted tree: next to each vertex, the number of vertices in its subtree

Input

The first line contains a positive integer $n$. Each of the next $n - 1$ lines contains two positive integers: $u$ and $v$ — the vertices joined by an edge.

Output

One line: $n$ space-separated integers — the subtree sizes of vertices $1$, $2$, …, $n$.

Note

$1 \le n \le 2 * 10^{5}$
$1 \le u, v \le n$

Examples

Input #1
6
1 2
1 3
2 4
2 5
3 6
Output #1
6 3 2 1 1 1
Input #2
1
Output #2
1

Sign in to submit a solution

Signing up is free and takes a minute.