Buggy python submission (verdict: Runtime Error):
import sys
from collections import deque
inputs = sys.stdin.readlines()

n = int(inputs[0])
edges = [tuple(map(int, x.split())) for x in inputs[1:]]
B = [e[1] for e in edges] 

E = [[] for _ in range(N + 1)]
for a, b in edges:
    E[a].append(b)

Q = deque([1])
C = [0] * (N + 1)
while Q:
    v = Q.popleft()
    c = 0
    for u in E[v]:
        c += 1 + (c + 1 == C[v])
        C[u] = c
        Q.append(u)

print(max(C))
for b in B:
    print(C[b])

Fixed submission:
from collections import deque
 
N, *AB = map(int, open(0).read().split())
B = AB[1::2]
 
E = [[] for _ in range(N + 1)]
for a, b in zip(*[iter(AB)] * 2):
    E[a].append(b)

Q = deque([1])
C = [0] * (N + 1)
while Q:
    v = Q.popleft()
    c = 0
    for u in E[v]:
        c += 1 + (c + 1 == C[v])
        C[u] = c
        Q.append(u)

print(max(C))
for b in B:
    print(C[b])

Buggy python submission (verdict: Runtime Error):
from collections import deque
 
N, *AB = map(int, open(0).read().split())
B = AB[1::2]
 
E = [[] for _ in range(N)]
for a, b in zip(*[iter(AB)] * 2):
    E[a-1].append(b-1)

Q = deque([0])
C = [0] * (N)
while Q:
    v = Q.popleft()
    c = 0
    for u in E[v]:
        c += c == C[v]
        C[u] = c
        Q.append(u)

print(max(C)+1)
for b in B:
    print(C[b]+1)

Fixed submission:
from collections import deque
 
N, *AB = map(int, open(0).read().split())
B = AB[1::2]
 
E = [[] for _ in range(N + 1)]
for a, b in zip(*[iter(AB)] * 2):
    E[a].append(b)

Q = deque([1])
C = [0] * (N + 1)
while Q:
    v = Q.popleft()
    c = 0
    for u in E[v]:
        c += 1 + (c + 1 == C[v])
        C[u] = c
        Q.append(u)

print(max(C))
for b in B:
    print(C[b])

Buggy python submission (verdict: Runtime Error):
import sys
from collections import deque, OrderedDict
inputs = sys.stdin.readlines()

n = int(inputs[0])
edges = [tuple(map(int, x.split())) for x in inputs[1:]]

tree, colors = [[] for _ in range(n)], OrderedDict()
for x, y in edges:
    tree[x-1].append(y-1)
    tree[y-1].append(x-1)
    colors[(x-1, y-1)] = 0
use_color = max(len(x) for x in tree)

queue, passed = deque([0]), set()
while queue:
    x = queue.popleft()
    passed.add(x)
    pallet = [i for i in range(use_color)][::-1]
    for y in tree[x]:
        if y in passed:
            if (x, y) in colors:
                pallet.remove(colors[(x, y)])
            elif (y, x) in colors:
                pallet.remove(colors[(y, x)])
            continue
        if (x, y) in colors:
            colors[(x, y)] = pallet.pop()
        elif (y, x) in colors:
            colors[(y, x)] = pallet.pop()
        queue.append(y)

print(use_color)
for c in colors.values():
    print(c+1)

Fixed submission:
from collections import deque
 
N, *AB = map(int, open(0).read().split())
B = AB[1::2]
 
E = [[] for _ in range(N + 1)]
for a, b in zip(*[iter(AB)] * 2):
    E[a].append(b)

Q = deque([1])
C = [0] * (N + 1)
while Q:
    v = Q.popleft()
    c = 0
    for u in E[v]:
        c += 1 + (c + 1 == C[v])
        C[u] = c
        Q.append(u)

print(max(C))
for b in B:
    print(C[b])

Buggy python submission (verdict: Runtime Error):
import sys
from collections import deque, OrderedDict
inputs = sys.stdin.readlines()

n = int(inputs[0])
edges = [tuple(map(int, x.split())) for x in inputs[1:]]

tree, colors = [[] for _ in range(n)], OrderedDict()
for x, y in edges:
    tree[x-1].append(y-1)
    tree[y-1].append(x-1)
    colors[(x-1, y-1)] = 0
use_color = max(len(x) for x in tree)

queue, passed = deque([0]), set()
while queue:
    x = queue.popleft()
    passed.add(x)
    pallet = [i for i in range(use_color)][::-1]
    for y in tree[x]:
        if y in passed:
            if (x, y) in colors:
                pallet.remove(colors[(x, y)])
            if (y, x) in colors:
                pallet.remove(colors[(y, x)])
            continue
        colors[(x, y)] = pallet.pop()
        queue.append(y)

print(use_color)
for c in colors.values():
    print(c+1)

Fixed submission:
from collections import deque
 
N, *AB = map(int, open(0).read().split())
B = AB[1::2]
 
E = [[] for _ in range(N + 1)]
for a, b in zip(*[iter(AB)] * 2):
    E[a].append(b)

Q = deque([1])
C = [0] * (N + 1)
while Q:
    v = Q.popleft()
    c = 0
    for u in E[v]:
        c += 1 + (c + 1 == C[v])
        C[u] = c
        Q.append(u)

print(max(C))
for b in B:
    print(C[b])

Buggy python submission (verdict: Runtime Error):
import sys
from collections import deque
inputs = sys.stdin.readlines()

n = int(inputs[0])
edges = [tuple(map(int, x.split())) for x in inputs[1:]]

tree, colors = [[] for _ in range(n)], dict()
for x, y in edges:
    tree[x-1].append(y-1)
    tree[y-1].append(x-1)
    colors[(x-1, y-1)] = 0
use_color = max(len(x) for x in tree)

queue, passed = deque([0]), set()
while queue:
    x = queue.popleft()
    passed.add(x)
    pallet = [i for i in range(use_color)][::-1]
    for y in tree[x]:
        if y in passed:
            if (x, y) in colors:
                pallet.remove(colors[(x, y)])
            if (y, x) in colors:
                pallet.remove(colors[(y, x)])
            continue
        colors[(x, y)] = pallet.pop()
        queue.append(y)

print(use_color)
for c in colors.values():
    print(c+1)

Fixed submission:
from collections import deque
 
N, *AB = map(int, open(0).read().split())
B = AB[1::2]
 
E = [[] for _ in range(N + 1)]
for a, b in zip(*[iter(AB)] * 2):
    E[a].append(b)

Q = deque([1])
C = [0] * (N + 1)
while Q:
    v = Q.popleft()
    c = 0
    for u in E[v]:
        c += 1 + (c + 1 == C[v])
        C[u] = c
        Q.append(u)

print(max(C))
for b in B:
    print(C[b])