import java.util.*;

public class Main {
    private static final Scanner sc = new Scanner(System.in);
    private static int[] readIntArray(Scanner s, int n) {
        int[] ans = new int[n];
        for (int i = 0; i < n; i++) {
            ans[i] = sc.nextInt();
        }
        return ans;
    }



    
    public static void main(String[] args) {
        int n = sc.nextInt();
        int[] deg = new int[n];
        int[] u = new int[n-1];
        int[] v = new int[n-1];
        for (int i = 0; i <= n-2; i++) {
            u[i] = sc.nextInt() - 1;
            v[i] = sc.nextInt() - 1;
            deg[u[i]]++;
            deg[v[i]]++;
        }
        int numberOfLeaves = 0;
        for (int i = 0; i < n; i++) if (deg[i] == 1) numberOfLeaves++;
        int nonLeaf = numberOfLeaves;
        int leaf = 0;
        if (numberOfLeaves <= 2)
            for (int i = 0; i <= n-2; i++) System.out.println(i);
        else for (int i = 0; i <= n-2; i++) {
            if (deg[u[i]] == 1 || deg[v[i]] == 1) System.out.println(leaf++);
            else System.out.println(nonLeaf++);
        }
    }
}