Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
G=[[] for i in range(N)]
a=[]
b=[]

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

k=[0]*N

from collections import deque

q=deque([0])
C=[[-1]*N for i in range(N)]
p=[-1]*N

kmx=0
while q:
    x=q.popleft()
    for i in G[x]:
        if C[x][i]!=-1:continue
        if p[x]==k[x]:
            k[x]+=1

        C[x][i] = k[x]
        C[i][x] = k[x]
        p[i] = k[x]
        k[x] += 1
        kmx=max(kmx,k[x])
        q.append(i)

print(kmx)
for i in range(N-1):
    print(C[a[i]][b[i]]+1)




Fixed submission:
N=int(input())
G=[[] for i in range(N)]
a=[]
b=[]

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

k=[0]*N

from collections import deque

q=deque([0])
visited=[0]*N
ans={}
p=[-1]*N

kmx=0
while q:
    x=q.popleft()
    visited[x]=1
    cnt=1
    for i in G[x]:
        if visited[i]!=0:continue
        if p[x]==cnt:
            cnt+=1
        ans[(x,i)]=cnt
        ans[(i,x)]=cnt

        p[i] = cnt
        cnt += 1
        kmx=max(kmx,cnt-1)
        q.append(i)

print(kmx)
for i in range(N-1):
    print(ans[(a[i],b[i])])

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
G=[[] for i in range(N)]
a=[]
b=[]

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

L=[]
for i in G:
    L.append(len(i))

K=max(L)
print(K)

k=[0]*N

from collections import deque

q=deque([0])
C=[[-1]*N for i in range(N)]
p=[-1]*N

while q:
    x=q.popleft()
    for i in G[x]:
        if C[x][i]!=-1:continue
        if p[x]==k[x]:
            k[x]+=1

        C[x][i] = k[x]
        C[i][x] = k[x]
        p[i] = k[x]
        k[x] += 1


        q.append(i)

for i in range(N-1):
    print(C[a[i]][b[i]]+1)




Fixed submission:
N=int(input())
G=[[] for i in range(N)]
a=[]
b=[]

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

k=[0]*N

from collections import deque

q=deque([0])
visited=[0]*N
ans={}
p=[-1]*N

kmx=0
while q:
    x=q.popleft()
    visited[x]=1
    cnt=1
    for i in G[x]:
        if visited[i]!=0:continue
        if p[x]==cnt:
            cnt+=1
        ans[(x,i)]=cnt
        ans[(i,x)]=cnt

        p[i] = cnt
        cnt += 1
        kmx=max(kmx,cnt-1)
        q.append(i)

print(kmx)
for i in range(N-1):
    print(ans[(a[i],b[i])])

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
G=[[] for i in range(N)]
a=[]
b=[]

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

L=[]
for i in G:
    L.append(len(i))

K=max(L)
print(K)

k=[0]*N

from collections import deque

q=deque([0])
C=[[-1]*N for i in range(N)]
p=[-1]*N

while q:
    x=q.popleft()
    for i in G[x]:
        if C[x][i]!=-1:continue
        if p[x]==k[x]:
            k[x]+=1

        C[x][i] = k[x]
        C[i][x] = k[x]
        p[i] = k[x]
        k[x] += 1


        q.append(i)

for i in range(N-1):
    print(C[a[i]][b[i]]+1)




Fixed submission:
N=int(input())
G=[[] for i in range(N)]
a=[]
b=[]

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

k=[0]*N

from collections import deque

q=deque([0])
visited=[0]*N
ans={}
p=[-1]*N

kmx=0
while q:
    x=q.popleft()
    visited[x]=1
    cnt=1
    for i in G[x]:
        if visited[i]!=0:continue
        if p[x]==cnt:
            cnt+=1
        ans[(x,i)]=cnt
        ans[(i,x)]=cnt

        p[i] = cnt
        cnt += 1
        kmx=max(kmx,cnt-1)
        q.append(i)

print(kmx)
for i in range(N-1):
    print(ans[(a[i],b[i])])

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
G=[[] for i in range(N)]
a=[]
b=[]

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

L=[]
for i in G:
    L.append(len(i))

K=max(L)
print(K)

k=[[0]*K for i in range(N)]

from collections import deque

q=deque([0])
C=[[-1]*N for i in range(N)]

while q:
    x=q.popleft()
    for i in G[x]:
        if C[x][i]!=-1:continue
        for j in range(K):
            if k[x][j]==0:
                C[x][i]=j
                C[i][x]=j
                k[x][j]=1
                k[i][j]=1
                break
        q.append(i)

for i in range(N-1):
    print(C[a[i]][b[i]]+1)




Fixed submission:
N=int(input())
G=[[] for i in range(N)]
a=[]
b=[]

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

k=[0]*N

from collections import deque

q=deque([0])
visited=[0]*N
ans={}
p=[-1]*N

kmx=0
while q:
    x=q.popleft()
    visited[x]=1
    cnt=1
    for i in G[x]:
        if visited[i]!=0:continue
        if p[x]==cnt:
            cnt+=1
        ans[(x,i)]=cnt
        ans[(i,x)]=cnt

        p[i] = cnt
        cnt += 1
        kmx=max(kmx,cnt-1)
        q.append(i)

print(kmx)
for i in range(N-1):
    print(ans[(a[i],b[i])])

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
G=[[] for i in range(N)]
a=[]
b=[]

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

L=[]
for i in G:
    L.append(len(i))

K=max(L)
print(K)

k=[[0]*K for i in range(N)]

from collections import deque

q=deque([0])
C=[[-1]*N for i in range(N)]

while q:
    x=q.popleft()
    for i in G[x]:
        if C[x][i]!=-1:continue
        for j in range(K):
            if k[x][j]==0:
                C[x][i]=j
                C[i][x]=j
                k[x][j]=1
                k[i][j]=1
                break
        q.append(i)

for i in range(N-1):
    print(C[a[i]][b[i]]+1)




Fixed submission:
N=int(input())
G=[[] for i in range(N)]
a=[]
b=[]

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

k=[0]*N

from collections import deque

q=deque([0])
visited=[0]*N
ans={}
p=[-1]*N

kmx=0
while q:
    x=q.popleft()
    visited[x]=1
    cnt=1
    for i in G[x]:
        if visited[i]!=0:continue
        if p[x]==cnt:
            cnt+=1
        ans[(x,i)]=cnt
        ans[(i,x)]=cnt

        p[i] = cnt
        cnt += 1
        kmx=max(kmx,cnt-1)
        q.append(i)

print(kmx)
for i in range(N-1):
    print(ans[(a[i],b[i])])

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
R=[[] for i in range(N)]
a=[]
b=[]
L=[]

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

for i in range(N-1):
    L.append([len(R[i]),i])

L.sort(reverse=True)

K=L[0][0]

for i in range(N-1):
    if L[i][0]!=K:break
    if L[i][1] in b:
        K+=1
        break

print(K)

C=[[] for i in range(K)]
for i in range(N-1):
    for k in range(K):
        if (a[i] in C[k]) or (b[i] in C[k]):continue
        else:
            print(k+1)
            C[k].append(a[i])
            C[k].append(b[i])
            break



Fixed submission:
N=int(input())
G=[[] for i in range(N)]
a=[]
b=[]

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

k=[0]*N

from collections import deque

q=deque([0])
visited=[0]*N
ans={}
p=[-1]*N

kmx=0
while q:
    x=q.popleft()
    visited[x]=1
    cnt=1
    for i in G[x]:
        if visited[i]!=0:continue
        if p[x]==cnt:
            cnt+=1
        ans[(x,i)]=cnt
        ans[(i,x)]=cnt

        p[i] = cnt
        cnt += 1
        kmx=max(kmx,cnt-1)
        q.append(i)

print(kmx)
for i in range(N-1):
    print(ans[(a[i],b[i])])