n = int(input())

freqs = [0 for i in range(n)]
uv_pairs = []
for i in range(n-1):
    u, v = map(int, input().split())
    u -= 1
    v -= 1
    freqs[u] += 1
    freqs[v] += 1
    uv_pairs.append((u, v))

mn = 0
mx = n-2
for i in range(n-1):
    u, v = uv_pairs[i]
    if freqs[u] == 1 or freqs[v] == 1:
        print(mn)
        mn += 1
    else:
        print(mx)
        mx -= 1
