Buggy python submission (verdict: Runtime Error):
from collections import deque

N = int(input())
edges = {i: [] for i in range(N)}
for _ in range(M-1):
    x, y, z = map(int, input().split())
    edges[x-1].append((y-1, z%2))
    edges[y-1].append((x-1, z%2))
color = [None]*N

q = deque([(0, 0)])
while q:
    v, c = q.popleft()
    color[v] = c
    for u, w in edges[v]:
        if color[u] is None:
            if w == 0:
                q.append((u, c))
            else:
                q.append((u, c^1))
print(*color, sep='\n')

Fixed submission:
from collections import deque

N = int(input())
edges = {i: [] for i in range(N)}
for _ in range(N-1):
    x, y, z = map(int, input().split())
    edges[x-1].append((y-1, z%2))
    edges[y-1].append((x-1, z%2))
color = [None]*N

q = deque([(0, 0)])
while q:
    v, c = q.popleft()
    color[v] = c
    for u, w in edges[v]:
        if color[u] is None:
            if w == 0:
                q.append((u, c))
            else:
                q.append((u, c^1))
print(*color, sep='\n')

Buggy python submission (verdict: Runtime Error):
from collections import deque

N = int(input())
edges = {i: [] for i in range(N)}
for _ in range(M-1):
    x, y, z = map(int, input().split())
    edges[x-1].append((y-1, z%2))
    edges[y-1].append((x-1, z%2))
color = [None]*N

q = deque([(0, 0)])
while q:
    v, c = q.popleft()
    color[v] = c
    for u, w in edges[v]:
        if color[u] is None:
            if w == 0:
                q.append((u, c))
            else:
                q.append((u, c^1))
print(*color, sep='\n')

Fixed submission:
from collections import deque

N = int(input())
edges = {i: [] for i in range(N)}
for _ in range(N-1):
    x, y, z = map(int, input().split())
    edges[x-1].append((y-1, z%2))
    edges[y-1].append((x-1, z%2))
color = [None]*N

q = deque([(0, 0)])
while q:
    v, c = q.popleft()
    color[v] = c
    for u, w in edges[v]:
        if color[u] is None:
            if w == 0:
                q.append((u, c))
            else:
                q.append((u, c^1))
print(*color, sep='\n')

Buggy python submission (verdict: Runtime Error):
from collections import deque

N = int(input())
edges = {i: [] for i in range(N)}
for _ in range(M-1):
    x, y, z = map(int, input().split())
    edges[x-1].append((y-1, z%2))
    edges[y-1].append((x-1, z%2))
color = [None]*N

q = deque([(0, 0)])
while q:
    v, c = q.popleft()
    color[v] = c
    for u, w in edges[v]:
        if color[u] is None:
            if w == 0:
                q.append((u, c))
            else:
                q.append((u, c^1))
print(*color, sep='\n')

Fixed submission:
from collections import deque

N = int(input())
edges = {i: [] for i in range(N)}
for _ in range(N-1):
    x, y, z = map(int, input().split())
    edges[x-1].append((y-1, z%2))
    edges[y-1].append((x-1, z%2))
color = [None]*N

q = deque([(0, 0)])
while q:
    v, c = q.popleft()
    color[v] = c
    for u, w in edges[v]:
        if color[u] is None:
            if w == 0:
                q.append((u, c))
            else:
                q.append((u, c^1))
print(*color, sep='\n')

Buggy python submission (verdict: Runtime Error):
N = int(input())
edge = sorted([tuple(map(int, input().split())) for _ in range(N)])
color = [0]*N

for u, v, w in edge:
    if w % 2 == 1 and color[u-1] == color[v-1]:
        color[v-1] ^= 1
    elif w % 2 == 0 and color[u-1] != color[v-1]:
        color[v-1] ^= 1

print(*color, sep='\n')

Fixed submission:
from collections import deque

N = int(input())
edges = {i: [] for i in range(N)}
for _ in range(N-1):
    x, y, z = map(int, input().split())
    edges[x-1].append((y-1, z%2))
    edges[y-1].append((x-1, z%2))
color = [None]*N

q = deque([(0, 0)])
while q:
    v, c = q.popleft()
    color[v] = c
    for u, w in edges[v]:
        if color[u] is None:
            if w == 0:
                q.append((u, c))
            else:
                q.append((u, c^1))
print(*color, sep='\n')