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