n=int(input())
g=[0]*(n+1)
p=[]
for i in range(n-1):
    a,b=map(int,input().split())
    g[a]+=1
    g[b]+=1
    p.append([a,b])
cnt=0
mex=n-2
for a,b in p:
    if(g[a]==1 or g[b]==1):
        print(cnt)
        cnt+=1
    else:
        print(mex)
        mex-=1