Problem p02850 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**6)

n = int(input())
ab = [list(map(int, input().split())) for i in range(n-1)]
ab2 = [[] for i in range(n)]
for i in range(n-1):
  ab2[ab[i][0]-1].append([ab[i][1]-1, i])
  ab2[ab[i][1]-1].append([ab[i][0]-1, i])
coloring = [0]*(n-1)

def f(x, y, z):
  c = 0
  for i in ab2[x]:
    if i[0] != y:
      c += 1
      if c == z:
        c += 1
      coloring[i[1]] = c
      x1 = i[0]
      y1 = x
      z1 = c
      f(x1, y1, z1)

f(0, None, None)
print(max(coloring))
for i in range(n-1):
  print(coloring[i])

Buggy submission (verdict: Runtime Error):
n = int(input())
ab = [list(map(int, input().split())) for i in range(n-1)]
ab2 = [[] for i in range(n)]
for i in range(n-1):
  ab2[ab[i][0]-1].append([ab[i][1]-1, i])
  ab2[ab[i][1]-1].append([ab[i][0]-1, i])
coloring = [0]*(n-1)

def f(x, y, z):
  c = 0
  for i in ab2[x]:
    if i[0] != y:
      c += 1
      if c == z:
        c += 1
      coloring[i[1]] = c
      x1 = i[0]
      y1 = x
      z1 = c
      f(x1, y1, z1)

f(0, None, None)
print(max(coloring))
for i in range(n-1):
  print(coloring[i])

Buggy submission (verdict: Runtime Error):
n = int(input())
ab = [list(map(int, input().split())) for i in range(n-1)]
ab2 = [[] for i in range(n)]
for i in range(n-1):
  ab2[ab[i][0]-1].append([ab[i][1]-1, i])
  ab2[ab[i][1]-1].append([ab[i][0]-1, i])
coloring = [0]*(n-1)
uc = [set() for i in range(n)]

def f(x, y):
  for i in ab2[x]:
    if i[0] != y:
      c = 1
      while c in uc[x]:
        c += 1
      coloring[i[1]] = c
      uc[x].add(c)
      uc[i[0]].add(c)
      x1 = i[0]
      y1 = x
      f(x1, y1)

f(0, 0)
print(max(coloring))
for i in range(n-1):
  print(coloring[i])

Buggy submission (verdict: Runtime Error):
n = int(input())
ab = [list(map(int, (str(i)+' '+input()).split())) for i in range(n-1)]
coloring = [0]*(n-1)
uc = [set() for _ in range(n)]

def f(x, y):
  for i in ab:
    x1 = i[1]+i[2]-x
    if x == i[1] or x == i[2] and y != x1:
      c = 1
      while c in uc[x-1]:
        c += 1
      uc[x-1].add(c)
      uc[x1-1].add(c)
      coloring[i[0]] = c
      f(x1, x)
f(1, 0)
print(max(coloring))
for i in range(n-1):
  print(coloring[i])

Buggy submission (verdict: Runtime Error):
n = int(input())
ab = [set(map(int, input().split())) for i in range(n-1)]
coloring = [0]*(n-1)
uc = [set() for _ in range(n)]

def f(x):
  for i in ab:
    if x in i:
      c = 1
      while c in uc[x-1]:
        c += 1
      y = sum(i)-x
      uc[x-1].add(c)
      uc[y-1].add(c)
      num = ab.index(i)
      coloring[num] = c
      ab[num] = set()
      f(y)
f(1)
print(max(coloring))
for i in range(n-1):
  print(coloring[i])

Buggy submission (verdict: Runtime Error):
n = int(input())
ab = [list(map(int, input().split())) for i in range(n-1)]
count = [0]*n
for i in range(n-1):
  count[ab[i][0]-1] += 1
  count[ab[i][1]-1] += 1
color = max(count)
print(color)
uc = [[0]*color for i in range(n)]
for i in range(n-1):
  j = 0
  while (uc[ab[i][0]-1][j] | uc[ab[i][1]-1][j]):
    j+=1
  else:
    print(j+1)
    uc[ab[i][0]-1][j] = 1
    uc[ab[i][1]-1][j] = 1

Buggy submission (verdict: Runtime Error):
a, b, x = map(int, input().split())
def pb(y):
  return(b*int(len(str(y))))

def p(y):
  return(a*y + pb(y))

def by(y):
  l = 1
  for j in range(y):
    l = 10*l
  return(l)

if x >= p(by(9)):
  print(by(9))
elif x < p(1):
  print(0)
else:
  for i in range(9):
    if p(by(i)) <= x < p(by(i+1)):
      ans = int((x-pb(by(i)))/a)
      if ans < by(i+1):
        print(ans)
      else:
        print(by(i+1)-1)
      break