Problem p02850 (python)

Fixed submission:
import sys
sys.setrecursionlimit(500000)
N = int(input())
E = [[] for _ in range(N+1)]
for i in range(N-1):
    a, b = map(int, input().split())
    E[a].append((b, i))
    E[b].append((a, i))
K = max(len(e) for e in E)
print(K)
Ans = [-1] * (N-1)
def dfs(v=1, p=0, p_col=-1):
    col = 1
    for u, idx in E[v]:
        if u!=p:
            if col == p_col:
                col += 1
            Ans[idx] = col
            dfs(u, v, col)
            col += 1
dfs()
print("\n".join(map(str, Ans)))

Buggy submission (verdict: Runtime Error):
N = int(input())
E = [[] for _ in range(N+1)]
for n in range(N-1):
    a,b = map(int, input().split())
    E[a].append((b,n))
    E[b].append((a,n))

K = max(len(e) for e in E)
print(K)

res = [-1 for _ in range(N-1)]
def dfs(v=1, p=0, p_col=-1):
    col = 1
    for child, idx in E[v]:
        if(child != p):
            if(col == p_col):
                col += 1
            res[idx] = col
            dfs(child,v,col)
            col += 1
dfs()
print("\n".join(map(str, res)))

Buggy submission (verdict: Runtime Error):
N = int(input())
E = [[] for _ in range(N+1)]
for n in range(N-1):
    a,b = map(int, input().split())
    E[a].append((b,n))
    E[b].append((a,n))

K = max(len(e) for e in E)
print(K)

res = [-1 for _ in range(N-1)]
def dfs(v=1, p=0, p_col=-1):
    col = 1
    for child, idx in E[v]:
        if(child != p):
            if(col == p_col):
                col += 1
            res[idx] = col
            dps(child,v,col)
            col += 1
dfs()
print("\n".join(map(str, res)))

Buggy submission (verdict: Runtime Error):
N = int(input())
E = [[] for _ in range(N+1)]
for n in range(N-1):
    a,b = map(int, input().split())
    E[a].append((b,n))
    E[b].append((a,n))

K = max(len(e) for e in E)
print(K)

res = [-1 for _ in range(N-1)]
def dps(v=1, p=0, p_col=-1):
    col = 1
    for child, idx in E[v]:
        if(child != p):
            if(col == p_col):
                col += 1
            res[idx] = col
            dps(child,v,col)
            col += 1
dps()
print("\n".join(map(str, res)))

Buggy submission (verdict: Runtime Error):
N = int(input())
E = [[] for _ in range(N)]
for n in range(N-1):
    a,b = map(int, input().split())
    a -= 1; b -= 1
    E[a].append((b,n))
    E[b].append((a,n))

K = max(len(e) for e in E)
print(K)

res = [-1]*(N-1)
def dps(v=0, p=-1, p_col=-1):
    col = 1
    for child, idx in E[v]:
        if(child != p):
            if(col == p_col):
                col += 1
            res[idx] = col
            dps(child,v,col)
            col += 1
dps()
print("\n".join(map(str, res)))

Buggy submission (verdict: Runtime Error):
N = int(input())
E = [[] for _ in range(N)]
for n in range(N-1):
    a,b = map(int, input().split())
    a -= 1; b -= 1
    E[a].append((b,n))
    E[b].append((a,n))

K = max(len(e) for e in E)
print(K)

res = [-1 for _ in range(N-1)]
def dps(v=0, p=-1, p_col=-1):
    col = 1
    for child, idx in E[v]:
        if(child != p):
            if(col == p_col):
                col += 1
            res[idx] = col
            dps(child,v,col)
            col += 1
dps()
print("\n".join(map(str, res)))

Buggy submission (verdict: Runtime Error):
import numpy as np

N = int(input())
E = np.zeros([N-1,2])
for n in range(N-1):
    temp = input().split()
    E[n,0]=int(temp[0])-1
    E[n,1] = int(temp[1])-1
starts = []; ends = []
for n in range(N-1):
    starts.append(E[n,0])
    ends.append(E[n,1])
edges = np.zeros([N-1])
for i in range(N-1):
    edges[i] = starts.count(i)+ends.count(i)
K = int(max(edges))
iro = np.zeros([N-1])
iro_set = [[] for i in range(N)]
for i in range(N-1):
    start = int(E[i,0]); end = int(E[i,1])
    kouho = list(range(1,K+1))
    for sude in iro_set[start]:
        kouho.remove(sude)
    for sude in iro_set[end]:
        kouho.remove(sude)
    iro[i] = kouho[0]
    iro_set[start].append(kouho[0])
    iro_set[end].append(kouho[0])
print(K)
for i in range(N-1):
    print(int(iro[i]))