Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
N=int(input())
G=[[] for n in range(N)]
E=[]
color_map={}
for n in range(N-1):
    a,b=map(int,input().split())
    E.append((a-1,b-1))
    color_map[(a-1,b-1)]=0
    G[a-1].append(b-1)
    G[b-1].append(a-1)
deg=[len(v) for v in G]
K=max(deg)
Q=deque([0])
X=[]

while Q:
    v=Q.popleft()
    X.append(v)
    for u in set(G[v])-set(X):
        Q.append(u)
    if v!=0:
        p=(set(X)&set(G[v])).pop()
        colors=set(range(1,K+1))
        for q in G[p]:
            p1,q1=min(p,q),max(p,q)
            colors-={color_map[(p1,q1)]}
        a,b=min(p,v),max(p,v)
        color_map[(a,b)]=colors.pop()
print(K)
for edge in E:
    print(color_map[edge])


Fixed submission:
from collections import deque

N=int(input())
G=[[] for n in range(N)]
E=[]
for n in range(N-1):
    a,b=map(int,input().split())
    E.append((a-1,b-1))
    G[a-1].append(b-1)
    G[b-1].append(a-1)
K=max([len(v) for v in G])

P=[-1]*N
Q=[0]
X=[]
count=0
while Q:
    v=Q.pop()
    X.append(v)
    for u in G[v]:
        if u==P[v]:
            continue
        P[u]=v
        Q.append(u)

C={}
for v in X:
    color=0
    try:
        p_color=C[tuple(sorted((v,P[v])))]
    except:
        p_color=-1
    for u in G[v]:
        if u==P[v]:
            continue
        if color==p_color:
            color+=1
        C[tuple(sorted((u,v)))]=color
        color+=1

print(K)
for e in E:
    print(C[e]+1)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
G=[[] for n in range(N)]
E=[]
color_map={}
for n in range(N-1):
    a,b=map(int,input().split())
    E.append((a-1,b-1))
    color_map[(a-1,b-1)]=0
    G[a-1].append(b-1)
    G[b-1].append(a-1)
deg=[len(v) for v in G]
K=max(deg)
Q=[0]
X=[]

while Q!=[]:
    v=Q.pop(0)
    X.append(v)
    for u in G[v]:
        if u not in X:
            Q.append(u)
    if v!=0:
        p=(set(X)&set(G[v])).pop()
        colors=set(range(1,K+1))
        for q in G[p]:
            p1,q1=min(p,q),max(p,q)
            colors-={color_map[(p1,q1)]}
        a,b=min(p,v),max(p,v)
        color_map[(a,b)]=colors.pop()
print(K)
for edge in E:
    print(color_map[edge])


Fixed submission:
from collections import deque

N=int(input())
G=[[] for n in range(N)]
E=[]
for n in range(N-1):
    a,b=map(int,input().split())
    E.append((a-1,b-1))
    G[a-1].append(b-1)
    G[b-1].append(a-1)
K=max([len(v) for v in G])

P=[-1]*N
Q=[0]
X=[]
count=0
while Q:
    v=Q.pop()
    X.append(v)
    for u in G[v]:
        if u==P[v]:
            continue
        P[u]=v
        Q.append(u)

C={}
for v in X:
    color=0
    try:
        p_color=C[tuple(sorted((v,P[v])))]
    except:
        p_color=-1
    for u in G[v]:
        if u==P[v]:
            continue
        if color==p_color:
            color+=1
        C[tuple(sorted((u,v)))]=color
        color+=1

print(K)
for e in E:
    print(C[e]+1)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
G=[[] for n in range(N)]
E=[]
for n in range(N-1):
    a,b=map(int,input().split())
    E.append((a-1,b-1))
    G[a-1].append(b-1)
    G[b-1].append(a-1)
deg=[len(v) for v in G]
K=max(deg)
Q=[0]
X=[]
color_map={}
while Q!=[]:
    v=Q.pop(0)
    X.append(v)
    for u in G[v]:
        if u not in X:
            Q.append(u)
    if v!=0:
        p=(set(X)&set(G[v])).pop()
        colors=set(range(1,K+1))
        for edge in color_map.keys():
            if p in edge:
                colors-={color_map[edge]}
        a,b=min(p,v),max(p,v)
        color_map[(a,b)]=colors.pop()
print(K)
for edge in E:
    print(color_map[edge])


Fixed submission:
from collections import deque

N=int(input())
G=[[] for n in range(N)]
E=[]
for n in range(N-1):
    a,b=map(int,input().split())
    E.append((a-1,b-1))
    G[a-1].append(b-1)
    G[b-1].append(a-1)
K=max([len(v) for v in G])

P=[-1]*N
Q=[0]
X=[]
count=0
while Q:
    v=Q.pop()
    X.append(v)
    for u in G[v]:
        if u==P[v]:
            continue
        P[u]=v
        Q.append(u)

C={}
for v in X:
    color=0
    try:
        p_color=C[tuple(sorted((v,P[v])))]
    except:
        p_color=-1
    for u in G[v]:
        if u==P[v]:
            continue
        if color==p_color:
            color+=1
        C[tuple(sorted((u,v)))]=color
        color+=1

print(K)
for e in E:
    print(C[e]+1)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
G=[[] for n in range(N)]
E=[]
color_map={}
for n in range(N-1):
    a,b=map(int,input().split())
    E.append((a-1,b-1))
    color_map[(a-1,b-1)]=0
    G[a-1].append(b-1)
    G[b-1].append(a-1)
deg=[len(v) for v in G]
K=max(deg)
Q=[0]
X=[]
while Q!=[]:
    v=Q.pop(0)
    X.append(v)
    for u in G[v]:
        if u not in X:
            Q.append(u)
    if v!=0:
        p=(set(X)&set(G[v])).pop()
        colors=set(range(1,K+1))
        for edge in E:
            if p in edge:
                colors-={color_map[edge]}
        a,b=min(p,v),max(p,v)
        color_map[(a,b)]=colors.pop()
print(K)
for edge in E:
    print(color_map[edge])


Fixed submission:
from collections import deque

N=int(input())
G=[[] for n in range(N)]
E=[]
for n in range(N-1):
    a,b=map(int,input().split())
    E.append((a-1,b-1))
    G[a-1].append(b-1)
    G[b-1].append(a-1)
K=max([len(v) for v in G])

P=[-1]*N
Q=[0]
X=[]
count=0
while Q:
    v=Q.pop()
    X.append(v)
    for u in G[v]:
        if u==P[v]:
            continue
        P[u]=v
        Q.append(u)

C={}
for v in X:
    color=0
    try:
        p_color=C[tuple(sorted((v,P[v])))]
    except:
        p_color=-1
    for u in G[v]:
        if u==P[v]:
            continue
        if color==p_color:
            color+=1
        C[tuple(sorted((u,v)))]=color
        color+=1

print(K)
for e in E:
    print(C[e]+1)

Buggy python submission (verdict: Runtime Error):
import copy
N=int(input())
G=[[] for n in range(N)]
E=[]
for n in range(N-1):
    a,b=map(int,input().split())
    E.append((a-1,b-1))
    G[a-1].append(b-1)
    G[b-1].append(a-1)

deg=[len(v) for v in G]
K=max(deg)
Q=copy.copy(G[0])
X=[0]
C=[0]*N
color_map={}
while Q!=[]:
    v=Q.pop(0)
    X.append(v)
    colors=list(range(1,K+1))
    for u in G[v]:
        if C[u] in colors:
            colors.remove(C[u])
        for w in G[u]:
            if C[w] in colors:
                colors.remove(C[w])
        if u not in X:
            Q.append(u)
    color=copy.copy(colors[0])
    C[v]=color
    p=list(set(X)&set(G[v]))[0]
    color_map[(min(p,v),max(p,v))]=color

print(K)
for e in E:
    print(color_map[e])


Fixed submission:
from collections import deque

N=int(input())
G=[[] for n in range(N)]
E=[]
for n in range(N-1):
    a,b=map(int,input().split())
    E.append((a-1,b-1))
    G[a-1].append(b-1)
    G[b-1].append(a-1)
K=max([len(v) for v in G])

P=[-1]*N
Q=[0]
X=[]
count=0
while Q:
    v=Q.pop()
    X.append(v)
    for u in G[v]:
        if u==P[v]:
            continue
        P[u]=v
        Q.append(u)

C={}
for v in X:
    color=0
    try:
        p_color=C[tuple(sorted((v,P[v])))]
    except:
        p_color=-1
    for u in G[v]:
        if u==P[v]:
            continue
        if color==p_color:
            color+=1
        C[tuple(sorted((u,v)))]=color
        color+=1

print(K)
for e in E:
    print(C[e]+1)