August 24, 2021
import sys
from collections import deque
input = sys.stdin.readline
n = int(input())
graph = [[] for _ in range(n + 1)]
visit = [0] * (n + 1)
parent = [0] * (n + 1)
for _ in range(n - 1):
x, y = list(map(int, input().split()))
graph[x].append(y)
graph[y].append(x)
def bfs(x):
queue = deque([x])
visit[x] = True
while queue:
v = queue.popleft()
for i in graph[v]:
if not visit[i]:
queue.append(i)
visit[i] = True
parent[i] = v
bfs(1)
for i in range(2, n + 1):
print(parent[i])