n = int(input())
d = dict()
a = list()
for i in range(n - 1):
    a.append(-1)
    u, v = map(int, input().split())
    if u in d.keys():
        d[u].append(i)
    else:
        d[u] = list()
        d[u].append(i)

    if v in d.keys():
        d[v].append(i)
    else:
        d[v] = list()
        d[v].append(i)
ans = 0
c = 0
#
# b = list()
for i in range(n - 1):
    # b.append(0)
    # a.append((len(d[i + 1]), i))
    if len(d[i + 1]) == 1:
        a[i] = c
        c += 1
# a.sort(reverse=True)
# print(a)
c = n - 2
for i in range(n - 1):
    # b[a[i][1]] = c
    # c -= 1
    if a[i] == -1:
        print(c)
        c -= 1
    else:
        print(a[i])
# for i in range(n - 1):
#     print(b[i])
print(d)

