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

~/algor $ cat problems/daraxt-otalari

Parents in a tree

Easy 1000 ms 128 MB 33%
Share

A tree with $n$ vertices numbered from $1$ to $n$ is given. The tree is rooted at vertex $1$. The parent of every vertex other than the root is the first neighbouring vertex on the path from it to the root. Find the parents of vertices $2$, $3$, …, $n$.

A tree rooted at the first vertex: an arrow from each vertex to its parent

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 - 1$ space-separated numbers — the parents of vertices $2$, $3$, …, $n$.

Note

$2 \le n \le 10^{5}$
$1 \le u, v \le n$
The given edges form a tree.

Examples

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

Sign in to submit a solution

Signing up is free and takes a minute.