I = lambda : map(int,input().split())

n= int(input())
l=[-1]*(n-1);g=[0]*(10**5+2)
x=[];d={}
for _ in range(n-1):
    a,b=I()
    d[a]=d.get(a,0)+1
    d[b]=d.get(b,0)+1
    x.append([a,b])
for i in d.keys():
    if d[i]==1:
        g[i]=1
k=0
for i in range(n-1):
    if g[x[i][0]] or g[x[i][1]]:
        l[i]=k
        k+=1
for i in range(n-1):
    if l[i]==-1:
        l[i]=k
        k+=1
print(*l)