Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
n = int(input())
l = [0 for i in range(n)]
l2 = []
l3 = [[] for i in range(n+1)]
for i in range(n-1):
    a,b = map(int,input().split())
    l2.append([a,b])
    l3[a].append(b)
    l3[b].append(a)
    l[a-1] += 1
    l[b-1] += 1
a = max(l)
print(a)
rl = [0 for i in range(n+1)]
d = deque()
d.append([1,0])
rl[1] = 1
cl = [[0 for i in range(n+1)] for i in range(n+1)]
while len(d):
    now,c = d.popleft()
    rl[now] = 1
    if c == 0:
        count = 1
        for i in l3[now]:
            cl[now][i] = count
            d.append([i,count])
            count += 1
    else:
        count = 1
        for i in l3[now]:
            if rl[i] == 0:
                if c == count:
                    count += 1
                cl[now][i] = count
                d.append([i,count])
                count += 1
for i in range(n-1):
    print(cl[l2[i][0]][l2[i][1]])

Fixed submission:
from collections import deque
n = int(input())
l = [0 for i in range(n)]
l2 = []
l3 = [[] for i in range(n+1)]
for i in range(n-1):
    a,b = map(int,input().split())
    l2.append([a,b])
    l3[a].append(b)
    l3[b].append(a)
    l[a-1] += 1
    l[b-1] += 1
a = max(l)
print(a)
rl = [0 for i in range(n+1)]
d = deque()
d.append([1,0])
rl[1] = 1
dic = {}
while len(d):
    now,c = d.popleft()
    rl[now] = 1
    if c == 0:
        count = 1
        for i in l3[now]:
            dic["{0},{1}".format(now,i)] = count
            d.append([i,count])
            count += 1
    else:
        count = 1
        for i in l3[now]:
            if rl[i] == 0:
                if c == count:
                    count += 1
                dic["{0},{1}".format(now,i)] = count
                d.append([i,count])
                count += 1
for i in range(n-1):
    print(dic["{0},{1}".format(l2[i][0],l2[i][1])])

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
n = int(input())
l = [0 for i in range(n)]
l2 = []
l3 = [[] for i in range(n+1)]
for i in range(n-1):
    a,b = map(int,input().split())
    l2.append([a,b])
    l3[a].append(b)
    l3[b].append(a)
    l[a-1] += 1
    l[b-1] += 1
a = max(l)
print(a)
rl = [0 for i in range(n+1)]
d = deque()
d.append([1,0])
rl[1] = 1
cl = [[0 for i in range(n+1)] for i in range(n+1)]
while len(d):
    now,c = d.popleft()
    rl[now] = 1
    if c == 0:
        count = 1
        for i in l3[now]:
            cl[now][i] = count
            d.append([i,count])
            count += 1
    else:
        count = 1
        for i in l3[now]:
            if rl[i] == 0:
                if c == count:
                    count += 1
                cl[now][i] = count
                d.append([i,count])
                count += 1
for i in range(n-1):
    print(cl[l2[i][0]][l2[i][1]])

Fixed submission:
from collections import deque
n = int(input())
l = [0 for i in range(n)]
l2 = []
l3 = [[] for i in range(n+1)]
for i in range(n-1):
    a,b = map(int,input().split())
    l2.append([a,b])
    l3[a].append(b)
    l3[b].append(a)
    l[a-1] += 1
    l[b-1] += 1
a = max(l)
print(a)
rl = [0 for i in range(n+1)]
d = deque()
d.append([1,0])
rl[1] = 1
dic = {}
while len(d):
    now,c = d.popleft()
    rl[now] = 1
    if c == 0:
        count = 1
        for i in l3[now]:
            dic["{0},{1}".format(now,i)] = count
            d.append([i,count])
            count += 1
    else:
        count = 1
        for i in l3[now]:
            if rl[i] == 0:
                if c == count:
                    count += 1
                dic["{0},{1}".format(now,i)] = count
                d.append([i,count])
                count += 1
for i in range(n-1):
    print(dic["{0},{1}".format(l2[i][0],l2[i][1])])