Buggy python submission (verdict: Runtime Error):
import sys
from collections import defaultdict
N = int(input())


sys.setrecursionlimit(10000)

uvw = [[int(item) for item in input().split()] for _ in range(N-1)]

d = defaultdict(lambda: {})
for u, v, w in uvw:
    d[u][v] = w
    d[v][u] = w


dist = {1: 0}


def calc_dist(i, up):
    if not(i in dist):
        dist[i] = dist[up]+d[up][i]
        [calc_dist(k, i) for k in list(d[i].keys())]


[calc_dist(k, 1) for k in list(d[1].keys())]

for i in range(1, N+1):
    if dist[i] % 2 == 0:
        print(0)
    else:
        print(1)


Fixed submission:
import sys
from collections import defaultdict
N = int(input())


sys.setrecursionlimit(1000000)

uvw = [[int(item) for item in input().split()] for _ in range(N-1)]

d = defaultdict(lambda: {})
for u, v, w in uvw:
    d[u][v] = w
    d[v][u] = w


dist = {1: 0}


def calc_dist(i, up):
    if not(i in dist):
        dist[i] = dist[up]+d[up][i]
        [calc_dist(k, i) for k in list(d[i].keys())]


[calc_dist(k, 1) for k in list(d[1].keys())]

for i in range(1, N+1):
    if dist[i] % 2 == 0:
        print(0)
    else:
        print(1)

Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
N = int(input())

uvw = [[int(item) for item in input().split()] for _ in range(N-1)]

d = defaultdict(lambda: {})
for u, v, w in uvw:
    d[u][v] = w
    d[v][u] = w


dist = {1: 0}


def calc_dist(i, up):
    if not(i in dist):
        dist[i] = dist[up]+d[up][i]
        [calc_dist(k, i) for k in list(d[i].keys())]


[calc_dist(k, 1) for k in list(d[1].keys())]

for i in range(1, N+1):
    if dist[i] % 2 == 0:
        print(0)
    else:
        print(1)


Fixed submission:
import sys
from collections import defaultdict
N = int(input())


sys.setrecursionlimit(1000000)

uvw = [[int(item) for item in input().split()] for _ in range(N-1)]

d = defaultdict(lambda: {})
for u, v, w in uvw:
    d[u][v] = w
    d[v][u] = w


dist = {1: 0}


def calc_dist(i, up):
    if not(i in dist):
        dist[i] = dist[up]+d[up][i]
        [calc_dist(k, i) for k in list(d[i].keys())]


[calc_dist(k, 1) for k in list(d[1].keys())]

for i in range(1, N+1):
    if dist[i] % 2 == 0:
        print(0)
    else:
        print(1)

Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
N = int(input())

color = [-1]*N

uvw = [[int(item) for item in input().split()] for _ in range(N-1)]

d = defaultdict(lambda: [])
for u, v, w in uvw:
    if w % 2 == 1:
        d[u].append(v)
        d[v].append(u)


def set_color(color, i, up=None):
    if color[i-1] == -1:
        if up is None:
            color[i-1] = 0
        else:
            color[i-1] = int(not color[up-1])
        for child in d[i]:
            color = set_color(color, child, i)
    return color


for k in d:
    color = set_color(color, k)


for i in range(N):
    print(max(color[i], 0))


Fixed submission:
import sys
from collections import defaultdict
N = int(input())


sys.setrecursionlimit(1000000)

uvw = [[int(item) for item in input().split()] for _ in range(N-1)]

d = defaultdict(lambda: {})
for u, v, w in uvw:
    d[u][v] = w
    d[v][u] = w


dist = {1: 0}


def calc_dist(i, up):
    if not(i in dist):
        dist[i] = dist[up]+d[up][i]
        [calc_dist(k, i) for k in list(d[i].keys())]


[calc_dist(k, 1) for k in list(d[1].keys())]

for i in range(1, N+1):
    if dist[i] % 2 == 0:
        print(0)
    else:
        print(1)

Buggy python submission (verdict: Runtime Error):
N = int(input())

color = [0]*N

uvw = [[int(item) for item in input().split()] for _ in range(N-1)]

for u, v, w in uvw:
    if w % 2 == 1:
        color[v-1] = int(not color[u-1])

for i in range(N):
    print(color[N])


Fixed submission:
import sys
from collections import defaultdict
N = int(input())


sys.setrecursionlimit(1000000)

uvw = [[int(item) for item in input().split()] for _ in range(N-1)]

d = defaultdict(lambda: {})
for u, v, w in uvw:
    d[u][v] = w
    d[v][u] = w


dist = {1: 0}


def calc_dist(i, up):
    if not(i in dist):
        dist[i] = dist[up]+d[up][i]
        [calc_dist(k, i) for k in list(d[i].keys())]


[calc_dist(k, 1) for k in list(d[1].keys())]

for i in range(1, N+1):
    if dist[i] % 2 == 0:
        print(0)
    else:
        print(1)