n = int(input())
dp = [0]*(n+1)
data = []
for _ in range(n-1):
    x,y = map(int,input().split())
    dp[x-1] += 1
    dp[y-1] += 1
    data.append([x-1,y-1])
count,rev = 0,n-2
for x,y in data:
    if(dp[x] == 1 or dp[y] == 1):
        print(count)
        count += 1
    else:
        print(rev)
        rev -= 1