Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
AB=[list(map(int,input().split())) for i in range(N-1)]
l=[[] for i in range(N)]
e=[0]*(N-1)
for i,(a,b) in enumerate(AB):
    l[a-1].append(i)
    l[b-1].append(i)
from collections import deque
q=deque([1])
e[0]=1
m=10**6
M=1
while q:
    pc=q.popleft()
    p,c=pc//m,pc%m
    for vn in AB[p]:
        x=1
        for en in l[vn-1]:
            if e[en]==0:
                if x==c:
                    x=c+1
                q.append(en*m+x)
                e[en]=x
                M=max(M,x)
                x+=1
print(M)
print(*e,sep='\n')

Fixed submission:
N=int(input())
AB=[list(map(int,input().split())) for i in range(N-1)]
l=[[] for i in range(N)]
e=[0]*(N-1)
for i,(a,b) in enumerate(AB):
    l[a-1].append((b-1,i))
    l[b-1].append((a-1,i))
from collections import deque
q=deque([(AB[0][0]-1,1),(AB[0][1]-1,1)])
e[0]=1
M=1
while q:
    vp,c=q.popleft()
    x=1
    for vn,en in l[vp]:
        if e[en]==0:
            if x==c:
                x=c+1
            q.append((vn,x))
            e[en]=x
            M=max(M,x)
            x+=1
print(M)
print(*e,sep='\n')

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
AB=[list(map(int,input().split())) for i in range(N-1)]
l=[[] for i in range(N)]
e=[0]*(N-1)
for i,(a,b) in enumerate(AB):
    l[a-1].append(i)
    l[b-1].append(i)
from collections import deque
q=deque([1])
e[0]=1
m=10**6
while q:
    pc=q.popleft()
    p,c=pc//m,pc%m
    for vn in AB[p]:
        x=1
        for en in l[vn-1]:
            if e[en]==0:
                if x==c:
                    x=c+1
                q.append(en*m+x)
                e[en]=x
                x+=1
print(*([max(e)]+e),sep='\n')

Fixed submission:
N=int(input())
AB=[list(map(int,input().split())) for i in range(N-1)]
l=[[] for i in range(N)]
e=[0]*(N-1)
for i,(a,b) in enumerate(AB):
    l[a-1].append((b-1,i))
    l[b-1].append((a-1,i))
from collections import deque
q=deque([(AB[0][0]-1,1),(AB[0][1]-1,1)])
e[0]=1
M=1
while q:
    vp,c=q.popleft()
    x=1
    for vn,en in l[vp]:
        if e[en]==0:
            if x==c:
                x=c+1
            q.append((vn,x))
            e[en]=x
            M=max(M,x)
            x+=1
print(M)
print(*e,sep='\n')

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
AB=[list(map(int,input().split())) for i in range(N-1)]
l=[[] for i in range(N)]
e=[0]*(N-1)
for i,(a,b) in enumerate(AB):
    l[a-1].append(i)
    l[b-1].append(i)
from collections import deque
q=deque([(0,1)])
e[0]=1
while q:
    p,c=q.popleft()
    for vn in AB[p]:
        x=1
        for en in l[vn-1]:
            if e[en]==0:
                if x==c:
                    x=c+1
                q.append((en,x))
                e[en]=x
                x+=1
print(*([max(e)]+e),sep='\n')

Fixed submission:
N=int(input())
AB=[list(map(int,input().split())) for i in range(N-1)]
l=[[] for i in range(N)]
e=[0]*(N-1)
for i,(a,b) in enumerate(AB):
    l[a-1].append((b-1,i))
    l[b-1].append((a-1,i))
from collections import deque
q=deque([(AB[0][0]-1,1),(AB[0][1]-1,1)])
e[0]=1
M=1
while q:
    vp,c=q.popleft()
    x=1
    for vn,en in l[vp]:
        if e[en]==0:
            if x==c:
                x=c+1
            q.append((vn,x))
            e[en]=x
            M=max(M,x)
            x+=1
print(M)
print(*e,sep='\n')