import java.io.*;
import java.util.*;
public class Main {
public static int N;
public static List<Integer>[] graph;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
N = Integer.parseInt(br.readLine());
graph = new List[N];
for (int i = 0; i < N; ++i) {
graph[i] = new ArrayList<>();
}
for (int i = 0; i < N - 1; ++i) {
String[] edgeInfo = br.readLine().split(" ");
int n1 = Integer.parseInt(edgeInfo[0]);
int n2 = Integer.parseInt(edgeInfo[1]);
n1--; n2--;
graph[n1].add(n2);
graph[n2].add(n1);
}
//bfs
int[] depths = bfs(0);
//result
StringBuilder sb = new StringBuilder();
for (int i = 1; i < N; ++i) {
int parentDepth = Integer.MAX_VALUE;
int parent = -1;
for (int adjNode : graph[i]) {
int adjDepth = depths[adjNode];
if (adjDepth < parentDepth) {
parentDepth = adjDepth;
parent = adjNode;
}
}
sb.append(parent + 1);
sb.append('\n');
}
System.out.println(sb);
}
public static int[] bfs(int node) {
int[] depths = new int[N];
boolean[] visited = new boolean[N];
Queue<Integer[]> q = new LinkedList<>();
q.add(new Integer[]{node,1});
depths[node] = 1;
visited[node] = true;
while (!q.isEmpty()) {
Integer[] now = q.poll();
int nowNode = now[0];
int nowDepth = now[1];
for (int nxt : graph[nowNode]) {
if (!visited[nxt]) {
visited[nxt] = true;
q.add(new Integer[]{nxt, nowDepth + 1});
depths[nxt] = nowDepth + 1;
}
}
}
return depths;
}
}