import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.StringTokenizer;
ArrayList<Node> adjentNodes;
adjentNodes = new ArrayList<Node>();
public void addNode(Node item) {
static int[] anwser_Parent;
private static StringTokenizer st;
public static void main(String args[]) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bf = new BufferedWriter(new OutputStreamWriter(System.out));
int inputLen = Integer.parseInt(br.readLine());
anwser_Parent = new int[inputLen+1];
Node[] nodes = new Node[inputLen+1];
for(int i=0; i< nodes.length; i++) {
for (int i = 0; i < inputLen-1; i++) {
st = new StringTokenizer(br.readLine());
one = Integer.parseInt(st.nextToken());
two = Integer.parseInt(st.nextToken());
nodes[one].addNode(nodes[two]);
nodes[two].addNode(nodes[one]);
nodes[1].parent = nodes[1];
alertParent(nodes, nodes[1]);
for(int i=2; i<nodes.length; i++) {
bf.append(String.format("%d\n", anwser_Parent[i]));
private static void alertParent(Node[] node, Node current) {
for(Node child : current.adjentNodes) {
if(child.parent == null) {
alertParent(node, child);
anwser_Parent[child.no] = current.no;