import atexit
import io
import sys
import math
from collections import defaultdict

_INPUT_LINES = sys.stdin.read().splitlines()
raw_input = iter(_INPUT_LINES).next
_OUTPUT_BUFFER = io.BytesIO()
sys.stdout = _OUTPUT_BUFFER

@atexit.register
def write():
    sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
def find(u):
    global flag
    global k
    #print u
    global kk
    visit[u-1]=1
    for i in l[u]:
        if visit[i-1]==1:
            continue
        if flag==0:
            print k
            k+=1
            flag=1
        else:
            print kk
            kk-=1
            flag=0
    
        find(i)
def add(u,v):
   l[u].append(v) 
   l[v].append(u)
   
t=int(raw_input())
l=defaultdict(list)
first=0
for i in range(t-1):
    u,v=map(int,raw_input().split())
    if first==0:
        first=u
    add(u,v)
flag=0
k=0
kk=t-2
visit=[0]*t
find(first)