Problem p02850 (python)

Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**9)

N=int(input())
E=[[] for _ in range(N)]
for i in range(N-1):
  a,b = map(int, input().split())
  E[a-1].append((b-1,i))
ans=[[] for _ in range(N-1)]
def sub(p, n):
  m=1
  for b,i in E[p]:
    if m == n: m+=1
    ans[i]=m
    sub(b,m)
    m+=1
sub(0,0)
print(max(ans))
for a in ans:
  print(a)

Buggy submission (verdict: Runtime Error):

N = int(input())
E = [[] for _ in range(N)]
for i in range(N-1):
    a,b = map(int,input().split())
    a,b = a-1,b-1
    E[a].append([b,i])
 
ans = [None]*(N-1)
 
def paint(now,color):
    No = 1
    for (to, en) in E[now]:
        if No == color:
            No += 1
        ans[en] = No
        paint(to,No)
        No += 1
 
paint(0,0)
print(max(ans))
print(*ans, sep="\n")

Buggy submission (verdict: Runtime Error):
N=int(input())
E=[[] for _ in range(N)]
for i in range(N-1):
  a,b = map(int, input().split())
  E[a-1].append((b-1,i))
ans=[[] for _ in range(N-1)]
def sub(p, n):
  m=1
  for b,i in E[p]:
    if m == n: m+=1
    ans[i]=m
    sub(b,m)
    m+=1
sub(0,0)
print(max(ans))
print(*ans, sep="\n")

Buggy submission (verdict: Runtime Error):
N=int(input())
E=[[] for _ in range(N)]
for i in range(N-1):
  a,b = map(int, input().split())
  E[a-1].append((b-1,i))
ans=[[] for _ in range(N-1)]
def sub(p, n):
  m=1
  for b,i in E[p]:
    if m == n: m+=1
    ans[i]=m
    sub(b,m)
    m+=1
sub(0,0)
print(max(ans))
for a in ans:
  print(a)

Buggy submission (verdict: Runtime Error):
N=int(input())
E=[[] for _ in range(N)]
for i in range(N-1):
  a,b = map(int, input().split())
  E[a-1].append((b-1,i))
  E[b-1].append((a-1,i))
ans=[[] for _ in range(N-1)]
visitted=[False for _ in range(N)]
def sub(p, n):
  m=1
  visitted[p]=True
  for a,b in E[p]:
    if not visitted[a]:
      if m == n: m+=1
      ans[b]=m
      sub(a,m)
      m+=1
sub(0,0)
print(max(ans))
for a in ans:
  print(a)

Buggy submission (verdict: Runtime Error):
import numpy as np
N=int(input())
E=[[] for _ in range(N)]
for i in range(N-1):
  a,b = map(int, input().split())
  E[a-1].append((b-1,i))
  E[b-1].append((a-1,i))
ans= np.empty(N-1)
def sub(p, n):
  m=1
  for a,b in E[p]:
    if not ans[b]:
      if m == n: m+=1
      ans[b]=m
      sub(a,m)
      m+=1
sub(0,0)
print(max(ans))
for a in ans:
  print(a)

Buggy submission (verdict: Runtime Error):
N=int(input())
E=[[] for _ in range(N)]
for i in range(N-1):
  a,b = map(int, input().split())
  E[a-1].append((b-1,i))
  E[b-1].append((a-1,i))
ans=[[] for _ in range(N-1)]
def sub(p, n):
  m=1
  for a,b in E[p]:
    if not ans[b]:
      if m == n: m+=1
      ans[b]=m
      sub(a,m)
      m+=1
sub(0,0)
print(max(ans))
for a in ans:
  print(a)

Buggy submission (verdict: Runtime Error):
N=int(input())
E=[[] for _ in range(N)]
for i in range(N-1):
  a,b = map(int, input().split())
  E[a-1].append((b-1,i))
ans=[[] for _ in range(N-1)]
def sub(p, n):
  m=1
  for a,b in E[p]:
    if m == n: m+=1
    ans[b]=m
    sub(a,m)
    m+=1
sub(0,0)
print(max(ans))
for a in ans:
  print(a)

Buggy submission (verdict: Runtime Error):
N=int(input())
E=[[] for _ in range(N)]
for i in range(N-1):
  a,b = map(int, input().split())
  a,b = min(a-1,b-1),max(a-1,b-1)
  E[a].append((b,i))
ans=[[] for _ in range(N-1)]
def sub(p, n):
  m=1
  for a,b in E[p]:
    if m == n: m+=1
    ans[b]=m
    sub(a,m)
    m+=1
sub(0,0)
print(max(ans))
for a in ans:
  print(a)

Buggy submission (verdict: Runtime Error):
N=int(input())
E=[[] for _ in range(N-1)]
for i in range(N-1):
  a,b = map(int, input().split())
  E[a-1].append((b-1,i))
ans=[[] for _ in range(N-1)]
def sub(p, n):
  m=1
  for a,b in E[p]:
    if m == n: m+=1
    ans[b]=m
    sub(a,m)
    m+=1
sub(0,0)
print(max(ans))
for a in ans:
  print(a)