반응형
https://www.acmicpc.net/problem/11725
import collections
import sys
sys.setrecursionlimit(100000)
n = int(input())
edges = collections.defaultdict(list)
for i in range(n-1):
a, b = map(int, input().split())
edges[a].append(b)
edges[b].append(a)
answer = [0]*(n+1)
visited = [False]*(n+1)
def search(node):
for elem in edges[node]:
if not visited[elem]:
visited[elem] = True
answer[elem] = node
search(elem)
visited[1] = True
search(1)
for i in range(2, n+1):
print(answer[i])
댓글