Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
# Your code here!
import sys
input=sys.stdin.readline

N=int(input())

node=[[0] for i in range(N)]
#print(node)
q=[]
for i in range(N-1):
    a,b=map(int,input().split())
    q.append([a-1,b-1,i])

q.sort(key=lambda x:x[0])

ans=0
for index in range(len(q)):
    frm,to,num=q[index][0],q[index][1],q[index][2]
    for i in range(1,10**5+1):
        if (i in node[frm]) or (i in node[to]):
            pass
        else:
            node[frm].append(i)
            node[to].append(i)
            q[index].append(i)
            ans=max(ans,i)
            break
            
print(ans)
q.sort(key=lambda x:x[2])
for item in q:
    print(item[3])

Fixed submission:
# coding: utf-8
# Your code here!
import sys
input=sys.stdin.readline

N=int(input())

q=[]

l=[[] for i in range(N)]

ans=[1]*N
ans[0]=0
#print(l)

for i in range(N-1):
    a,b=map(int,input().split())
    q.append([a-1,b-1])
    l[a-1].append(b-1)

mx=0
for index,item in enumerate(l):
    color=1
    while item:
        temp=item.pop(-1)
        if color==ans[index]:
            color+=1
        ans[temp]=color
        color+=1
    mx=max(color-1,mx)

print(mx)
for _,item in q:
    print(ans[item])

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
# Your code here!

from collections import deque
import sys
input=sys.stdin.readline

N=int(input())

node=[[0] for i in range(N)]
#print(node)
q=[]
for i in range(N-1):
    a,b=map(int,input().split())
    q.append([a-1,b-1,i])

q.sort(key=lambda x:x[0])

ans=0
for index in range(len(q)):
    frm,to,num=q[index][0],q[index][1],q[index][2]
    for i in range(1,10**6):
        if (i in node[frm]) or (i in node[to]):
            pass
        else:
            node[frm].append(i)
            node[to].append(i)
            q[index].append(i)
            ans=max(ans,i)
            break
            
print(ans)
q.sort(key=lambda x:x[2])
for item in q:
    print(item[3])

Fixed submission:
# coding: utf-8
# Your code here!
import sys
input=sys.stdin.readline

N=int(input())

q=[]

l=[[] for i in range(N)]

ans=[1]*N
ans[0]=0
#print(l)

for i in range(N-1):
    a,b=map(int,input().split())
    q.append([a-1,b-1])
    l[a-1].append(b-1)

mx=0
for index,item in enumerate(l):
    color=1
    while item:
        temp=item.pop(-1)
        if color==ans[index]:
            color+=1
        ans[temp]=color
        color+=1
    mx=max(color-1,mx)

print(mx)
for _,item in q:
    print(ans[item])

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
# Your code here!

from collections import deque
import sys
input=sys.stdin.readline

N=int(input())

node=[[0] for i in range(N)]
#print(node)
q=[]
for i in range(N-1):
    a,b=map(int,input().split())
    q.append([a-1,b-1,i])

q.sort(key=lambda x:x[0])

ans=0
for index in range(len(q)):
    frm,to,num=q[index][0],q[index][1],q[index][2]
    for i in range(1,10**6):
        if (i in node[frm]) or (i in node[to]):
            pass
        else:
            node[frm].append(i)
            node[to].append(i)
            q[index].append(i)
            ans=max(ans,i)
            break
            
print(ans)
q.sort(key=lambda x:x[2])
for item in q:
    print(item[3])

Fixed submission:
# coding: utf-8
# Your code here!
import sys
input=sys.stdin.readline

N=int(input())

q=[]

l=[[] for i in range(N)]

ans=[1]*N
ans[0]=0
#print(l)

for i in range(N-1):
    a,b=map(int,input().split())
    q.append([a-1,b-1])
    l[a-1].append(b-1)

mx=0
for index,item in enumerate(l):
    color=1
    while item:
        temp=item.pop(-1)
        if color==ans[index]:
            color+=1
        ans[temp]=color
        color+=1
    mx=max(color-1,mx)

print(mx)
for _,item in q:
    print(ans[item])