

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.StringTokenizer;
     
     
    public class hello2
     {static class FastReader 
           { 
               BufferedReader br; 
               StringTokenizer st; 
         
               public FastReader() 
               { 
                   br = new BufferedReader(new
                            InputStreamReader(System.in)); 
               } 
         
               String next() 
               { 
                   while (st == null || !st.hasMoreElements()) 
                   { 
                       try
                       { 
                           st = new StringTokenizer(br.readLine()); 
                       } 
                       catch (IOException  e) 
                       { 
                           e.printStackTrace(); 
                       } 
                   } 
                   return st.nextToken(); 
               } 
         
               int nextInt() 
               { 
                   return Integer.parseInt(next()); 
               } 
         
               long nextLong() 
               { 
                   return Long.parseLong(next()); 
               } 
         
               double nextDouble() 
               { 
                   return Double.parseDouble(next()); 
               } 
         
               String nextLine() 
               { 
                   String str = ""; 
                   try
                   { 
                       str = br.readLine(); 
                   } 
                   catch (IOException e) 
                   { 
                       e.printStackTrace(); 
                   } 
                   return str; 
               } 
             
           }
        
        static String sum (String s)
        {
            String s1 = ""; 
            
            if(s.contains("a"))
                s1+="a";
            if(s.contains("e"))
                s1+="e";
            if(s.contains("i"))
                s1+="i";
            if(s.contains("o"))
                s1+="o";
            if(s.contains("u"))
                s1+="u";
            
                return s1;
                
            
        }
        
     
        public static HashMap<String, Integer> sortByValue(HashMap<String, Integer> hm) 
        { 
            // Create a list from elements of HashMap 
            List<Map.Entry<String, Integer> > list = 
                   new LinkedList<Map.Entry<String, Integer> >(hm.entrySet()); 
      
            // Sort the list 
            Collections.sort(list, new Comparator<Map.Entry<String, Integer> >() { 
                public int compare(Map.Entry<String, Integer> o1,  
                                   Map.Entry<String, Integer> o2) 
                { 
                    return (o1.getValue()).compareTo(o2.getValue()); 
                } 
            }); 
              
            // put data from sorted list to hashmap  
            HashMap<String, Integer> temp = new LinkedHashMap<String, Integer>(); 
            for (Map.Entry<String, Integer> aa : list) { 
                temp.put(aa.getKey(), aa.getValue()); 
            } 
            return temp; 
        } 
        
        
public static void main(String args[])
{
	      FastReader input  =new FastReader();
	      
	     
	      
	      int n = input.nextInt();
	      
	      ArrayList<Integer> arr[] = new ArrayList[n+1];
	      
	     
	      for(int i=1;i<=n;i++)
	      {
	    	  	arr[i] = new ArrayList();
	      }
	      int root =0;
	      
	      for(int i=1;i<=n-1;i++)
	      {
	    	  int x = input.nextInt();
	    	  int y = input.nextInt();
	    	  
	    	  if(i==1)
	    		  root = x;
	    	  
	    	  arr[x].add(y);
	    	  
	    	 // System.out.println(x + "  " + y);
	      }
	      

    	//  System.out.println(root);
	      
	      
	      Queue<Integer> q = new LinkedList<Integer>();
	      
	      q.add(root);

	      int count =0;
	      int l=0;
	      int r=0;
	      
	      
	      while(!q.isEmpty())
	      {
	    	  
	    	  int x = q.poll();
	    	  
	    	  //System.out.println(x);
	    	  
	    	  for(int i=0;i<arr[x].size();i++)
	    	  {
	    		  
	    		  if(count%2==1)
		    		  {
		    			  System.out.println(n-2-l);
		    			  l++;
		    		  }
		    		  else
		    			  {
		    			  	System.out.println(0+r);
		    			  	r++;
		    			  }
		    		  
		    		  count++;
		    		  
		    		  
		    		 
		    		  q.add(arr[x].get(i));
	    			  
	    		  
	    		  
	    	  }
	    	  
	      }
	      
	      
	      
	      
	    
	      
	      
	      
	     
	      
	      
	      
	      
	      
	      
	      

	      
	      
	      
	      
	      
	     
	      
	      
	      
      
}
        
       
     
       
        
       
    
       
       
       
        
        
            
            

     
     
        
            
     
            
       
            
            
            
            
     
    	
     
    
     
    static long gcd(long a,long b)
    {
    	 if (a == 0)  
    	        return b;  
    	    return gcd(b % a, a);  
    }
    	
     
     
    static boolean find(int a[],int A,int B)
    	{
    		if( root(a,A)==root(a,B) )       //if A and B have the same root, it means that they are connected.
    			return true;
    		else
    			return false;
    	}
     
     
     
     
     
    	static void union(int Arr[],int size[],int A,int B)
    	{
    		int root_A = root(Arr,A);
    		int root_B = root(Arr,B);
    		
    		
    		if(root_A == root_B)
    		{
    			return;
    		}
    		if(size[root_A] < size[root_B] )
    		{
    			Arr[ root_A ] = Arr[root_B];
    			size[root_B] += size[root_A];
    			size[root_A] = 0;	
    			
    		}
    		else
    		{
    			Arr[ root_B ] = Arr[root_A];
    			size[root_A] += size[root_B];
    			size[root_B] = 0;
    			
     
    			
    			
    			
    		}
     
    	}
    	
    	
    	
    	static int root (int Arr[ ] ,int i)
    	{
    		while(Arr[ i ] != i)          
            {
    			i = Arr[ i ];
            }
            return i;
    	}
    	static long factorial(long n)
        {
            long fact = 1;
            for(int i=1;i<=n;i++)
            {
                fact*=i;
            }
            return fact;
        }
     }
     
   
     