Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
def bfs(si):
  q = deque()
  q.append([si,-1])
  used.add(si)
  while len(q)>0:
    prvi, prvcol = q.popleft()
    col = 1 
    for i in g[prvi]:
      if i in used:continue
      if col == prvcol: col += 1
      cols[eds.index(sorted([i,prvi]))] = col
      q.append([i,col])
      used.add(i)
      col += 1

N = int(input())
g = {i:[] for i in range(N)}
eds = []
for _ in range(N-1):
  a,b = map(int,input().split())
  eds.append([a-1,b-1])
  g[a-1].append(b-1)
  g[b-1].append(a-1)

cols = [-1 for _ in range(N-1)]
used = set([])
bfs(0)
print(max(cols))
[print(col) for col in cols]

Fixed submission:
from collections import deque
def bfs(si):
  q = deque()
  q.append([si,-1])
  used.add(si)
  while len(q)>0:
    prvi, prvcol = q.popleft()
    col = 1 
    for i in g[prvi]:
      if i in used:continue
      if col == prvcol: col += 1
      cols[eds[str(min(prvi,i))+'-'+str(max(prvi,i))]] = col
      q.append([i,col])
      used.add(i)
      col += 1

N = int(input())
g = {i:[] for i in range(N)}
eds = {}
for i in range(N-1):
  a,b = map(int,input().split())
  eds[str(a-1)+'-'+str(b-1)] = i
  g[a-1].append(b-1)
  g[b-1].append(a-1)

used = set([])
cols = [-1 for _ in range(N-1)]  
bfs(0)
print(max(cols))
[print(col) for col in cols]

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
def bfs(si):
  q = deque()
  q.append([si,-1])
  used.add(si)
  while len(q)>0:
    prvi, prvcol = q.popleft()
    used_col = [prvcol]
    for i in g[prvi]:
      if i in used:continue
      
      for coli in range(1,len(g[prvi])+1):
        if coli not in used_col:
          cols[eds.index(sorted([i,prvi]))] = coli
          used_col.append(coli)
          q.append([i,coli])
          used.add(i)
          break      

N = int(input())
g = {i:[] for i in range(N)}
eds = []
for _ in range(N-1):
  a,b = map(int,input().split())
  eds.append([a-1,b-1])
  g[a-1].append(b-1)
  g[b-1].append(a-1)

cols = [-1 for _ in range(N-1)]
used = set([])
bfs(0)
print(max(cols))
[print(col) for col in cols]

Fixed submission:
from collections import deque
def bfs(si):
  q = deque()
  q.append([si,-1])
  used.add(si)
  while len(q)>0:
    prvi, prvcol = q.popleft()
    col = 1 
    for i in g[prvi]:
      if i in used:continue
      if col == prvcol: col += 1
      cols[eds[str(min(prvi,i))+'-'+str(max(prvi,i))]] = col
      q.append([i,col])
      used.add(i)
      col += 1

N = int(input())
g = {i:[] for i in range(N)}
eds = {}
for i in range(N-1):
  a,b = map(int,input().split())
  eds[str(a-1)+'-'+str(b-1)] = i
  g[a-1].append(b-1)
  g[b-1].append(a-1)

used = set([])
cols = [-1 for _ in range(N-1)]  
bfs(0)
print(max(cols))
[print(col) for col in cols]

Buggy python submission (verdict: Runtime Error):
N = int(input())
g = {i:[] for i in range(N)}
AB = []
K = -float('inf')
for _ in range(N-1):
  a,b = map(int,input().split())
  AB.append([a-1,b-1])
  g[a-1].append(b-1)
  g[b-1].append(a-1)
  K = max(K,len(g[a-1]), len(g[b-1]))

print(K)
k = 1
print(k)
for i in range(1,N-1):
  a,b = AB[i]
  if (AB[i][0] in g[a-1] and AB[i][0] in g[b-1]) or (AB[i][1] in g[a-1] and AB[i][1] in g[b-1]):
    k +=1
    k = 1 if k==5 else k
  print(k)

Fixed submission:
from collections import deque
def bfs(si):
  q = deque()
  q.append([si,-1])
  used.add(si)
  while len(q)>0:
    prvi, prvcol = q.popleft()
    col = 1 
    for i in g[prvi]:
      if i in used:continue
      if col == prvcol: col += 1
      cols[eds[str(min(prvi,i))+'-'+str(max(prvi,i))]] = col
      q.append([i,col])
      used.add(i)
      col += 1

N = int(input())
g = {i:[] for i in range(N)}
eds = {}
for i in range(N-1):
  a,b = map(int,input().split())
  eds[str(a-1)+'-'+str(b-1)] = i
  g[a-1].append(b-1)
  g[b-1].append(a-1)

used = set([])
cols = [-1 for _ in range(N-1)]  
bfs(0)
print(max(cols))
[print(col) for col in cols]

Buggy python submission (verdict: Runtime Error):
N = int(input())
g = {i:[] for i in range(N)}
AB = []
K = -float('inf')
for _ in range(N-1):
  a,b = map(int,input().split())
  AB.append([a-1,b-1])
  g[a-1].append(b-1)
  g[b-1].append(a-1)
  K = max(K,len(g[a-1]), len(g[b-1]))

print(K)
k = 1
print(k)
for i in range(1,N-1):
  a,b = AB[i]
  if AB[i][0] in g[a-1] + g[b-1] or AB[i][1] in g[a-1] + g[b-1]:
    k +=1
    k = 1 if k==5 else k
  print(k)

Fixed submission:
from collections import deque
def bfs(si):
  q = deque()
  q.append([si,-1])
  used.add(si)
  while len(q)>0:
    prvi, prvcol = q.popleft()
    col = 1 
    for i in g[prvi]:
      if i in used:continue
      if col == prvcol: col += 1
      cols[eds[str(min(prvi,i))+'-'+str(max(prvi,i))]] = col
      q.append([i,col])
      used.add(i)
      col += 1

N = int(input())
g = {i:[] for i in range(N)}
eds = {}
for i in range(N-1):
  a,b = map(int,input().split())
  eds[str(a-1)+'-'+str(b-1)] = i
  g[a-1].append(b-1)
  g[b-1].append(a-1)

used = set([])
cols = [-1 for _ in range(N-1)]  
bfs(0)
print(max(cols))
[print(col) for col in cols]