https://www.acmicpc.net/problem/11725
#include <iostream>
#include <vector>
using namespace std;
static vector<int> arr[100001];
static int num[100001];
static bool check[100001];
static int n;
static int bf;
static void dfs(int a){
check[a]=true;
num[a]=bf;
for(int i:arr[a]){
if(check[i]==false){
bf=a;
dfs(i);
}
}
}
int main() {
cin >> n;
for(int i=0;i<n-1;i++){
int u,v;
cin >> u >> v;
arr[u].push_back(v);
arr[v].push_back(u);
}
bf=1;
dfs(1);
for(int i=2;i<=n;i++) cout << num[i] << "\n";
}