Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
N=int(input());AB=[list(map(int,input().split())) for _ in range(1,N)]
nd=[0 for _ in range(N)]
table = [[] for _ in range(N)]
for a,b in AB:
  table[a-1].append(b)
  nd[a-1]+=1
  nd[b-1]+=1

K=max(nd)
co=[0 for _ in range(N)]
for x,li in enumerate(table):
  c=[i for i in range(1,K+1) if i != co[x]]
  for b,y in zip(li,c):
    co[b-1]=y

print(K)
for _,b in AB:
  print(co[b-1])

Fixed submission:
import sys

input = sys.stdin.readline
N=int(input());AB=[tuple(map(int,input().split())) for _ in range(1,N)]

co=[0 for _ in range(N)]
prev=0
color=1
for a,b in sorted(AB):
  if prev!=a:
    color=1
  if co[a-1]==color:
    color+=1
  co[b-1]=color
  prev=a
  color+=1

print(max(co))
for _,b in AB:
  print(co[b-1])

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input());AB=[list(map(int,input().split())) for _ in range(1,N)]
nd=[0 for _ in range(N)]
table = [[] for _ in range(N)]
for a,b in AB:
  table[a-1].append(b)
  nd[a-1]+=1
  nd[b-1]+=1

K=max(nd)
co=[0 for _ in range(N)]
for x,li in enumerate(table):
  c=[i for i in range(1,K+1) if i != co[x]]
  for b,y in zip(li,c):
    co[b-1]=y

print(K)
for _,b in AB:
  print(co[b-1])


Fixed submission:
import sys

input = sys.stdin.readline
N=int(input());AB=[tuple(map(int,input().split())) for _ in range(1,N)]

co=[0 for _ in range(N)]
prev=0
color=1
for a,b in sorted(AB):
  if prev!=a:
    color=1
  if co[a-1]==color:
    color+=1
  co[b-1]=color
  prev=a
  color+=1

print(max(co))
for _,b in AB:
  print(co[b-1])

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input());AB=[list(map(int,input().split())) for _ in range(1,N)]
nd=[0 for _ in range(N)]
table = [[] for _ in range(N)]
for a,b in AB:
  table[a-1].append(b)
  nd[a-1]+=1
  nd[b-1]+=1

K=max(nd)
co=[0 for _ in range(N)]
ans=dict()
for x,li in enumerate(table):
  c=[i for i in range(1,K+1) if i != co[x]]
  for b,y in zip(li,c):
    co[b-1]=y
    ans[(x+1,b)]=y

print(K)
for a,b in AB:
  print(ans[(a,b)])


Fixed submission:
import sys

input = sys.stdin.readline
N=int(input());AB=[tuple(map(int,input().split())) for _ in range(1,N)]

co=[0 for _ in range(N)]
prev=0
color=1
for a,b in sorted(AB):
  if prev!=a:
    color=1
  if co[a-1]==color:
    color+=1
  co[b-1]=color
  prev=a
  color+=1

print(max(co))
for _,b in AB:
  print(co[b-1])

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input());AB=[list(map(int,input().split())) for _ in range(1,N)]
nd=[0 for _ in range(N)]
table = [[] for _ in range(N)]
for a,b in AB:
  table[a-1].append(b)
  nd[a-1]+=1
  nd[b-1]+=1

for li in table:
  li.sort()

K=max(nd)
print(K)
co=[0 for _ in range(N)]
ans=dict()
for x,li in enumerate(table):
  c=[i for i in range(1,K+1) if i != co[x]]
  for b,y in zip(li,c):
    co[b-1]=y
    ans[(x+1,b)]=y

for a,b in AB:
  print(ans[(a,b)])


Fixed submission:
import sys

input = sys.stdin.readline
N=int(input());AB=[tuple(map(int,input().split())) for _ in range(1,N)]

co=[0 for _ in range(N)]
prev=0
color=1
for a,b in sorted(AB):
  if prev!=a:
    color=1
  if co[a-1]==color:
    color+=1
  co[b-1]=color
  prev=a
  color+=1

print(max(co))
for _,b in AB:
  print(co[b-1])

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input());AB=[list(map(int,input().split())) for _ in range(1,N)]
nd=[0 for _ in range(N)]
table = [[] for _ in range(N)]
for a,b in AB:
  table[a-1].append(b)
  nd[a-1]+=1
  nd[b-1]+=1

for li in table:
  li.sort()

K=max(nd)
print(K)
co=[0 for _ in range(N)]
ans=dict()
for x,li in enumerate(table):
  c=[i for i in range(1,K+1) if i != co[x]]
  for b,y in zip(li,c):
    co[b-1]=y
    ans[(x+1,b)]=y

for a,b in AB:
  print(ans[(a,b)])


Fixed submission:
import sys

input = sys.stdin.readline
N=int(input());AB=[tuple(map(int,input().split())) for _ in range(1,N)]

co=[0 for _ in range(N)]
prev=0
color=1
for a,b in sorted(AB):
  if prev!=a:
    color=1
  if co[a-1]==color:
    color+=1
  co[b-1]=color
  prev=a
  color+=1

print(max(co))
for _,b in AB:
  print(co[b-1])

Buggy python submission (verdict: Runtime Error):
N=int(input());AB=[list(map(int,input().split())) for _ in range(1,N)]
nd=[0 for _ in range(N)]
table = [[] for _ in range(N)]
for a,b in AB:
  table[a-1].append(b)
  nd[a-1]+=1
  nd[b-1]+=1

for _,li in table:
  sort(li)

K=max(nd)
print(K)
co=[0 for _ in range(N)]
for x,li in enumerate(table):
  c=[i for i in range(1,K+1) if i != co[x]]
  for b,y in zip(li,c):
    co[b-1]=y
    print(y)


Fixed submission:
import sys

input = sys.stdin.readline
N=int(input());AB=[tuple(map(int,input().split())) for _ in range(1,N)]

co=[0 for _ in range(N)]
prev=0
color=1
for a,b in sorted(AB):
  if prev!=a:
    color=1
  if co[a-1]==color:
    color+=1
  co[b-1]=color
  prev=a
  color+=1

print(max(co))
for _,b in AB:
  print(co[b-1])

Buggy python submission (verdict: Runtime Error):
N=int(input());AB=[list(map(int,input().split())) for _ in range(1,N)]
nd=[0 for _ in range(N)]
table = [[] for _ in range(N)]
for a,b in AB:
  table[a-1].append(b)
  nd[a-1]+=1
  nd[b-1]+=1

for _,li in table:
  sort(li)

K=max(nd)
print(K)
co=[0 for _ in range(N)]
for x,li in enumerate(table):
  c=[i for i in range(1,K+1) if i != co[x]]
  for b,y in zip(li,c):
    co[b-1]=y
    print(y)


Fixed submission:
import sys

input = sys.stdin.readline
N=int(input());AB=[tuple(map(int,input().split())) for _ in range(1,N)]

co=[0 for _ in range(N)]
prev=0
color=1
for a,b in sorted(AB):
  if prev!=a:
    color=1
  if co[a-1]==color:
    color+=1
  co[b-1]=color
  prev=a
  color+=1

print(max(co))
for _,b in AB:
  print(co[b-1])