//package codeforces._628;

import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class _628_C {

    public static void main (String[] args) throws Exception {

//        String s = "6\n" +
//                "1 2\n" +
//                "1 3\n" +
//                "2 4\n" +
//                "2 5\n" +
//                "5 6";

        String s = "2\n" +
                "1 2";

        class Node implements Comparable<Node>{
            int id;
            Node next;
            Node prev;
            long counter = 0;
            int value;
            int order = Integer.MAX_VALUE;
            public int compareTo(Node o) {
                return Long.compare(o.counter, counter);
            }
        }

        Scanner scan = new Scanner(System.in);
//        Scanner scan = new Scanner(s);

        int n = scan.nextInt();

        Node[] nodes = new Node[n];

        for (int i=0; i<n-1; ++i) {
            int u = scan.nextInt() - 1;
            int v = scan.nextInt() - 1 ;
            if (nodes[u] == null) nodes[u] = new Node();
            if (nodes[v] == null) nodes[v] = new Node();
            nodes[v].order = i;
            nodes[v].id = v+1;
            nodes[u].id = u+1;
            nodes[u].next = nodes[v];
            nodes[v].prev = nodes[u];
        }

        for (Node node : nodes) {
            if (node.next == null) {
                Node _node = node;
                int counter = 0;
                while (_node.prev != null) {
                    counter++;
                    _node.counter += counter;
                    _node = _node.prev;
                }
            }
        }

        Arrays.sort(nodes);

        int v = n-2;
        for (int i=0; i<n-1; ++i) {
            nodes[i].value = v;
            v--;
        }

        Comparator<Node> comparator = new Comparator<Node>() {
            public int compare(Node o1, Node o2) {
                return o1.order - o2.order;
            }
        };

        Arrays.sort(nodes, comparator);

        for (int i=0; i<n-1; ++i) {
            System.out.println(nodes[i].value);
        }

    }

}