Problem p03044 (python)

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

def dfs(now):
    for to,dis in G[now]:
        if color[to] == -1:
            color[to] = (color[now] + dis) % 2
            dfs(to)

N = int(input())
G = [[] for _ in range(N)]
color = [-1] * N
color[0] = 0 #偶数=0

for i in range(N-1):
    a,b,c = map(int,input().split())
    a -= 1
    b -= 1
    G[a].append([b,c%2])
    G[b].append([a,c%2])

#print(G)    
dfs(0)
print(*color,sep="\n")

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10*9)

def dfs(now):
    for to,dis in G[now]:
        if color[to] == -1:
            color[to] = (color[now] + dis) % 2
            dfs(to)

N = int(input())
G = [[] for _ in range(N)]
color = [-1] * N
color[0] = 0 #偶数=0

for i in range(N-1):
    a,b,c = map(int,input().split())
    a -= 1
    b -= 1
    G[a].append([b,c%2])
    G[b].append([a,c%2])

#print(G)    
dfs(0)
print(*color,sep="\n")

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10*9)

def dfs(now):
    for to,dis in G[now]:
        if color[to] == -1:
            color[to] = (color[now] + dis) % 2
            dfs(to)

N = int(input())
G = [[] for _ in range(N)]
color = [-1] * N
color[0] = 1 #偶数=1

for i in range(N-1):
    a,b,c = map(int,input().split())
    a -= 1
    b -= 1
    G[a].append([b,c%2])
    G[b].append([a,c%2])

#print(G)    
dfs(0)
print(*color,sep="\n")

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10*9)

def dfs(now):
    for to,dis in G[now]:
        if color[to] == -1:
            color[to] = (color[now] + dis) % 2
            dfs(to)

N = int(input())
G = [[] for _ in range(N)]
color = [-1] * N
color[0] = 1 #偶数=０

for i in range(N-1):
    a,b,c = map(int,input().split())
    a -= 1
    b -= 1
    G[a].append([b,c%2])
    G[b].append([a,c%2])

#print(G)    
dfs(0)
for i in color:
    print(i)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10*9)

def dfs(now):
    for to,dis in G[now]:#next_v[0]=次の頂点、[1]=次までの距離
        if color[to]==-1:
            color[to]= (color[now] + dis) % 2
            dfs(to)

N = int(input())
G = [[] for _ in range(N)]
color = [-1] * N
color[0] = 1 #偶数=０

for i in range(N-1):
    a,b,c = map(int,input().split())
    a -= 1
    b -= 1
    G[a].append([b,c%2])
    G[b].append([a,c%2])

#print(G)    
dfs(0)
print(*color,sep="\n")

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10*9)

def dfs(now):
    for to,dis in G[now]:#next_v[0]=次の頂点、[1]=次までの距離
        if color[to]==-1:
            color[to]= (color[now] + dis) % 2
            dfs(to)

N = int(input())
G = [[] for _ in range(N)]
color = [-1] * N
color[0] = 1 #偶数=０

for i in range(N-1):
    a,b,c = map(int,input().split())
    a -= 1
    b -= 1
    G[a].append([b,c%2])
    G[b].append([a,c%2])

#print(G)    
dfs(0)
print(*color,sep="\n")

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10*7)

def dfs(now):
    for to,dis in G[now]:#next_v[0]=次の頂点、[1]=次までの距離
        if color[to]==-1:
            color[to]= (color[now] + dis) % 2
            dfs(to)

N = int(input())
G = [[] for _ in range(N)]
color = [-1] * N
color[0] = 1 #偶数=０

for i in range(N-1):
    a,b,c = map(int,input().split())
    a -= 1
    b -= 1
    G[a].append([b,c%2])
    G[b].append([a,c%2])

#print(G)    
dfs(0)
print(*color,sep="\n")

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10*7)

def dfs(G,v,color):
    #color[v] = True
    for next_v in G[v]:#next_v[0]=次の頂点、[1]=次までの距離
        if color[next_v[0]]==-1:
            color[next_v[0]] = (color[v] + next_v[1]) % 2 
            dfs(G,next_v[0],color)
        else:
            continue
    return color    

N = int(input())
G = [[] for _ in range(N)]
color = [-1] * N
color[0] = 0 #偶数=０

for i in range(N-1):
    a,b,c = map(int,input().split())
    a -= 1
    b -= 1
    G[a].append([b,c%2])
    G[b].append([a,c%2])

print(G)    
c = (dfs(G,0,color))
print(*c,sep="\n")