#include <iostream>
#include <queue>
#include <vector>
#define MAX 100001
using namespace std;
vector<int> adj[MAX];
bool isVisited[MAX] = {false};
int parent[MAX];
int n;
int main() {
cin.tie(NULL);
ios::sync_with_stdio(false);
cin >> n;
for (auto i=1; i<n; i++){
int a, b;
cin >> a >> b;
adj[a].push_back(b);
adj[b].push_back(a);
}
queue<int> q;
q.push(1);
while (!q.empty()){
int front = q.front();
q.pop();
isVisited[front] = true;
int size = adj[front].size();
for (int i =0; i<size; i++){
int node = adj[front][i];
if (!isVisited[node]){
parent[node] = front;
isVisited[node] = true;
q.push(node);
}
}
}
for (int i =2; i<=n; i++){
cout << parent[i] << '\n';
}
return 0;
}