# 11725번. 트리의 부모 찾기
fromcollectionsimportdequen=int(input())nList=[[]foriinrange(n+1)]foriinrange(n-1):a,b=map(int,input().split())nList[a].append(b)nList[b].append(a)q=deque([1])visited=[Falseforiinrange(n+1)]ans={}foriinrange(1,n+1):ans[i]=[]whileq:parent=q.popleft()forchildinnList[parent]:# 이 노드의 자식들
ifnotvisited[child]:ans[child]=parent# 부모를 저장해줌
q.append(child)visited[child]=Trueforiinrange(2,n+1):print(ans[i])