import java.util.*;
public class MEX {
    public static void main(String args[]) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        Node[] nodes = new Node[n];
        Edge[] edges = new Edge[n-1];
        for (int i = 0; i < n; i++) {
            nodes[i] = new Node(i);
        }
        for (int i = 0; i < n-1; i++) {
            int c1 = s.nextInt() - 1;
            int c2 = s.nextInt() - 1;
            edges[i] = new Edge(nodes[c1], nodes[c2]);
            nodes[c1].connect.add(edges[i]);
            nodes[c2].connect.add(edges[i]);
        }
        Node n1 = null;
        Node n2 = null;
        for (int i = 0; i < n; i++) {
            Node cur = nodes[i];
            if (cur.connect.size() == 1) {
                if (n1 == null) {
                    n1 = cur;
                }
                else {
                    n2 = cur;
                    break;
                }
            }
        }
        int count = n-2;
        for (int i = 0; i < n-1; i++) {
            if (edges[i].node1 != n1 && edges[i].node1 != n2 && edges[i].node2 != n1 && edges[i].node2 != n2) {
                edges[i].val = count;
                count--;
            }
        }
        boolean firstDone = false;
        for (int i = 0; i < n-1; i++) {
            if (edges[i].val == -1) {
                if (firstDone) {
                    System.out.print("1 ");
                }
                else {
                    System.out.print("0 ");
                    firstDone = true;
                }
            }
            else {
                System.out.print(edges[i].val + " ");
            }
        }
    }

    private static class Node {
        public ArrayList<Edge> connect;
        public int nodeNum;

        public Node(int nn) {
            this.nodeNum = nn;
            this.connect = new ArrayList<Edge>();
        }
    }

    private static class Edge {
        public Node node1;
        public Node node2;
        public int val;

        public Edge(Node n1, Node n2) {
            this.node1 = n1;
            this.node2 = n2;
            this.val = -1;
        }
    }
}
