링크 : https://www.acmicpc.net/problem/11725
/*
문제 : 트리의 부모 찾기
링크 : https://www.acmicpc.net/problem/11725
*/
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
vector<int> arr[100001];
bool visited[100001];
int parent[100001];
int N;
void dfs(int n){
if(!visited[n]) visited[n] = true;
for(int i = 0; i < arr[n].size(); i++){
int next = arr[n][i];
if(!visited[next]){
parent[next] = n;
dfs(next);
}
}
}
int main(){
cin >> N;
for(int i = 0; i < N-1; i++){
int a, b;
cin >> a >> b;
arr[a].push_back(b);
arr[b].push_back(a);
}
dfs(1);
for(int i = 2; i <= N; i++) cout << parent[i] << '\n';
return 0;
}