Buggy python submission (verdict: Runtime Error):
N = int(input())
edge = [[] for _ in range(N)]

for _ in range(N-1):
    u,v,w = map(int, input().split())
    w %= 2
    u, v = u-1, v-1
    edge[u].append((v,w))
    edge[v].append((u,w))

ret = [0] * N
def dfs(pv, v, dist):
    ret[v] = dist
    for nv, w in edge[v]:
        if nv == pv:
            continue
        dfs(v, nv, (dist+w)%2)

dfs(-1,0,0)
print(*ret, sep="\n")


Fixed submission:
import sys
sys.setrecursionlimit(10**9)
N = int(input())
a = [[] for _ in range(N)]
b = [[] for _ in range(N)]
for i in range(N-1):
    x, y, z = map(int, input().split())
    x, y, z = x-1, y-1, z % 2
    a[x].append([y, z])
    b[y].append([x, z])
dist = [0] * N
visited = [0] * N
print("")

def dfs(v, prev, dist, predist, visited):
    if visited[v]:
        return dist
    dist[v] = dist[prev] ^ predist
    visited[v] = 1
    for i in a[v]:
        dist = dfs(i[0], v, dist, i[1], visited)
    for i in b[v]:
        dist = dfs(i[0], v, dist, i[1], visited)
    return dist

dist = dfs(0, 0, dist, 0, visited)
for i in dist:
    print(i)

Buggy python submission (verdict: Runtime Error):
N = int(input())
edge = [[] for _ in range(N)]

for _ in range(N-1):
    u,v,w = map(int, input().split())
    w %= 2
    u, v = u-1, v-1
    edge[u].append((v,w))
    edge[v].append((u,w))

ret = [0] * N
def dfs(pv, v, dist):
    ret[v] = dist
    for nv, w in edge[v]:
        if nv == pv:
            continue
        dfs(v, nv, (dist+w)%2)

dfs(-1,0,0)
print(ret)


Fixed submission:
import sys
sys.setrecursionlimit(10**9)
N = int(input())
a = [[] for _ in range(N)]
b = [[] for _ in range(N)]
for i in range(N-1):
    x, y, z = map(int, input().split())
    x, y, z = x-1, y-1, z % 2
    a[x].append([y, z])
    b[y].append([x, z])
dist = [0] * N
visited = [0] * N
print("")

def dfs(v, prev, dist, predist, visited):
    if visited[v]:
        return dist
    dist[v] = dist[prev] ^ predist
    visited[v] = 1
    for i in a[v]:
        dist = dfs(i[0], v, dist, i[1], visited)
    for i in b[v]:
        dist = dfs(i[0], v, dist, i[1], visited)
    return dist

dist = dfs(0, 0, dist, 0, visited)
for i in dist:
    print(i)

Buggy python submission (verdict: Runtime Error):
N = int(input())
a = [[] for _ in range(N)]
b = [[] for _ in range(N)]
for i in range(N-1):
    x, y, z = map(int, input().split())
    x, y, z = x-1, y-1, z % 2
    a[x].append([y, z])
    b[y].append([x, z])
dist = [0] * N
visited = [0] * N
print("")

def dfs(v, prev, dist, predist, visited):
    if visited[v]:
        return dist
    dist[v] = dist[prev] ^ predist
    visited[v] = 1
    for i in a[v]:
        dist = dfs(i[0], v, dist, i[1], visited)
    for i in b[v]:
        dist = dfs(i[0], v, dist, i[1], visited)
    return dist

dist = dfs(0, 0, dist, 0, visited)
for i in dist:
    print(i)

Fixed submission:
import sys
sys.setrecursionlimit(10**9)
N = int(input())
a = [[] for _ in range(N)]
b = [[] for _ in range(N)]
for i in range(N-1):
    x, y, z = map(int, input().split())
    x, y, z = x-1, y-1, z % 2
    a[x].append([y, z])
    b[y].append([x, z])
dist = [0] * N
visited = [0] * N
print("")

def dfs(v, prev, dist, predist, visited):
    if visited[v]:
        return dist
    dist[v] = dist[prev] ^ predist
    visited[v] = 1
    for i in a[v]:
        dist = dfs(i[0], v, dist, i[1], visited)
    for i in b[v]:
        dist = dfs(i[0], v, dist, i[1], visited)
    return dist

dist = dfs(0, 0, dist, 0, visited)
for i in dist:
    print(i)