n = int(input())
d = [0]*(n + 1)
arr = []
for i1 in range(n - 1):
    c1, c2 = list(map(int, input().split()))
    d[c1] += 1
    d[c2] += 1
    arr.append([c1, c2])
start = 0
end = n - 2
for i1 in range(n - 1):
    if d[arr[i1][0]] == 1 or d[arr[i1][1]] == 1:
        print(start)
        start += 1
    else:
        print(end)
        end -= 1