난이도 : 실버 2
백준 문제
11725
코드 알고리즘
import sys
input = sys.stdin.readline
from collections import deque
myque = deque()
n = int(input())
cs = [[]for i in range(n+1)] #0번째에는 저장 안함
parents =[0]*(n+1)
checked = [0]*(n+1)
for i in range(n-1):
a, b = map(int, input().split())
cs[a].append(b)
cs[b].append(a)
myque.append(1)
checked[1]=1
def tree_parents():
while myque:
id = myque.popleft()
for j in cs[id]:
if checked[j] != 1:
parents[j]=id
checked[j] = 1
myque.append(j)
tree_parents()
for i in range(2, len(parents)):
print(parents[i])