https://www.acmicpc.net/problem/11725
import sys
sys.setrecursionlimit(10**6)
n=int(input())
arr=[[] for _ in range(n+1)]
num=[0]*(n+1)
check=[False]*(n+1)
for _ in range(n-1):
u,v=map(int,input().split())
arr[u].append(v)
arr[v].append(u)
bf=1
def dfs(a):
global bf
check[a]=True
num[a]=bf
for i in arr[a]:
if check[i]==False:
bf=a
dfs(i)
dfs(1)
for i in range(2,n+1):
print(num[i])