Buggy python submission (verdict: Runtime Error):
def clr(u):
    for x in G[u]:
        v,w = x[0],x[1]
        if hist[v]==0:
            if w%2==0:
                C[v] = C[u]
            else:
                C[v] = 1-C[u]
            hist[v]=1
            clr(v)      
N = int(input())
G = {i:[] for i in range(1,N+1)}
for _ in range(N-1):
    u,v,w = map(int,input().split())
    G[u].append((v,w))
    G[v].append((u,w))
C = [0 for i in range(N+1)]
hist = [0 for i in range(N+1)]
hist[1] = 1
clr(1)
for i in range(1,N+1):
    print(C[i])

Fixed submission:
from collections import deque
N = int(input())
G = {}
for _ in range(N-1):
    u,v,w = map(int,input().split())
    if u not in G:
        G[u] = []
    G[u].append((v,w%2))
    if v not in G:
        G[v] = []
    G[v].append((u,w%2))
que = deque([(1,0)])
hist = [0 for _ in range(N+1)]
hist[1] = 1
col = [0 for _ in range(N+1)]
while que:
    u,c = que.popleft()
    for x in G[u]:
        v,w = x[0],x[1]
        if hist[v]==0:
            if w==0:
                col[v] = c
                que.append((v,c))
            else:
                col[v] = 1-c
                que.append((v,1-c))
            hist[v] = 1
for i in range(1,N+1):
    print(col[i])

Buggy python submission (verdict: Runtime Error):
def col(i):
    for x in G[i]:
        v,w = x[0],x[1]
        if hist[v]==0:
            if w%2==0:
                C[v]=C[i]
            else:
                C[v]=1-C[i]
            hist[v] = 1
            col(v)
N = int(input())
G = {i:[] for i in range(1,N+1)}
for _ in range(N-1):
    u,v,w = map(int,input().split())
    G[u].append((v,w))
    G[v].append((u,w))
C = {i:0 for i in range(1,N+1)}
hist = [0 for i in range(N+1)]
hist[1] = 1
col(1)
for i in range(1,N+1):
    print(C[i])

Fixed submission:
from collections import deque
N = int(input())
G = {}
for _ in range(N-1):
    u,v,w = map(int,input().split())
    if u not in G:
        G[u] = []
    G[u].append((v,w%2))
    if v not in G:
        G[v] = []
    G[v].append((u,w%2))
que = deque([(1,0)])
hist = [0 for _ in range(N+1)]
hist[1] = 1
col = [0 for _ in range(N+1)]
while que:
    u,c = que.popleft()
    for x in G[u]:
        v,w = x[0],x[1]
        if hist[v]==0:
            if w==0:
                col[v] = c
                que.append((v,c))
            else:
                col[v] = 1-c
                que.append((v,1-c))
            hist[v] = 1
for i in range(1,N+1):
    print(col[i])

Buggy python submission (verdict: Runtime Error):
def col(i):
    for x in G[i]:
        v,w = x[0],x[1]
        if hist[v]==0:
            if w%2==0:
                C[v]=C[i]
            else:
                C[v]=1-C[i]
            hist[v] = 1
            col(v)
N = int(input())
G = {i:[] for i in range(1,N+1)}
for _ in range(N-1):
    u,v,w = map(int,input().split())
    G[u].append((v,w))
    G[v].append((u,w))
C = {i:0 for i in range(1,N+1)}
hist = [0 for i in range(N+1)]
hist[1] = 1
col(1)
for i in range(1,N+1):
    print(C[i])

Fixed submission:
from collections import deque
N = int(input())
G = {}
for _ in range(N-1):
    u,v,w = map(int,input().split())
    if u not in G:
        G[u] = []
    G[u].append((v,w%2))
    if v not in G:
        G[v] = []
    G[v].append((u,w%2))
que = deque([(1,0)])
hist = [0 for _ in range(N+1)]
hist[1] = 1
col = [0 for _ in range(N+1)]
while que:
    u,c = que.popleft()
    for x in G[u]:
        v,w = x[0],x[1]
        if hist[v]==0:
            if w==0:
                col[v] = c
                que.append((v,c))
            else:
                col[v] = 1-c
                que.append((v,1-c))
            hist[v] = 1
for i in range(1,N+1):
    print(col[i])