import java.util.*;
public class Test {
    static List<Integer> al[];
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        al = new ArrayList[n];
        for(int i=0; i<n; i++)
            al[i] = new ArrayList<Integer>();

        LinkedHashMap<Pair,Integer> hm = new LinkedHashMap<>();
        for(int i=0; i<n-1; i++){
            int x= sc.nextInt()-1;
            int y = sc.nextInt()-1;
            al[x].add(y);
            Pair p = new Pair(x,y);
            hm.put(p,0);
        }
            n--;
        for(Map.Entry<Pair,Integer> map : hm.entrySet()){
            Pair x = map.getKey();
            if(al[x.y].size()==0)
                hm.put(x,--n);
        }

        for(Map.Entry<Pair,Integer> map : hm.entrySet()){
            Pair x = map.getKey();
            if(al[x.y].size()!=0)
                hm.put(x,--n);
        }
        for(Map.Entry<Pair,Integer> map : hm.entrySet()) {
               System.out.println(map.getValue());
        }
    }
}
class Pair{
    int x;
    int y;
    Pair(int x, int y){
        this.x =x;
        this.y = y;
    }
}
