Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(20000)

N = int(input())
d = {}
e = [[] for _ in range(N)]
dd = [-1]*N
for _ in range(N-1):
    u, v, w = list(map(int, input().split()))
    e[u-1].append(v-1)
    e[v-1].append(u-1)
    d[(u-1,v-1)]= d[(v-1,u-1)] = w

def dfs(i, _d):
    dd[i] = _d
    for c in e[i]:
        if dd[c]!=-1: continue
        dfs(c, _d+d[(i,c)])

dfs(0,0)
for _dd in dd:
    print(_dd%2)

Fixed submission:
import sys
sys.setrecursionlimit(100000)

N = int(input())
d = {}
e = [[] for _ in range(N)]
dd = [-1]*N
for _ in range(N-1):
    u, v, w = list(map(int, input().split()))
    e[u-1].append(v-1)
    e[v-1].append(u-1)
    d[(u-1,v-1)]= d[(v-1,u-1)] = w

def dfs(i, _d):
    dd[i] = _d
    for c in e[i]:
        if dd[c]!=-1: continue
        dfs(c, _d+d[(i,c)])

dfs(0,0)
for _dd in dd:
    print(_dd%2)

Buggy python submission (verdict: Runtime Error):
N = int(input())
d = {}
e = [[] for _ in range(N)]
dd = [-1 for _ in range(N)]
for _ in range(N-1):
    u, v, w = list(map(int, input().split()))
    e[u-1].append(v-1)
    e[v-1].append(u-1)
    d[(u-1,v-1)]= d[(v-1,u-1)] = w

def dfs(i, _d):
    dd[i] = _d
    for c in e[i]:
        if dd[c]!=-1: continue
        dfs(c, _d+d[(i,c)])

dfs(0,0)
for _dd in dd:
    print(_dd%2)

Fixed submission:
import sys
sys.setrecursionlimit(100000)

N = int(input())
d = {}
e = [[] for _ in range(N)]
dd = [-1]*N
for _ in range(N-1):
    u, v, w = list(map(int, input().split()))
    e[u-1].append(v-1)
    e[v-1].append(u-1)
    d[(u-1,v-1)]= d[(v-1,u-1)] = w

def dfs(i, _d):
    dd[i] = _d
    for c in e[i]:
        if dd[c]!=-1: continue
        dfs(c, _d+d[(i,c)])

dfs(0,0)
for _dd in dd:
    print(_dd%2)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
d = [[-1 for _ in range(N)] for _ in range(N)]
e = [[] for _ in range(N)]
dd = [-1 for _ in range(N)]
for _ in range(N-1):
    u, v, w = list(map(int, input().split()))
    e[u-1].append(v-1)
    e[v-1].append(u-1)
    d[u-1][v-1] = d[v-1][u-1] = w

def dfs(i, _d):
    dd[i] = _d
    for c in e[i]:
        if dd[c]!=-1: continue
        dfs(c, _d+d[i][c])

dfs(0,0)
for _dd in dd:
    print(_dd%2)

Fixed submission:
import sys
sys.setrecursionlimit(100000)

N = int(input())
d = {}
e = [[] for _ in range(N)]
dd = [-1]*N
for _ in range(N-1):
    u, v, w = list(map(int, input().split()))
    e[u-1].append(v-1)
    e[v-1].append(u-1)
    d[(u-1,v-1)]= d[(v-1,u-1)] = w

def dfs(i, _d):
    dd[i] = _d
    for c in e[i]:
        if dd[c]!=-1: continue
        dfs(c, _d+d[(i,c)])

dfs(0,0)
for _dd in dd:
    print(_dd%2)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
r = [None]*N
s = 0

same = []
other = []

for _ in range(N-1):
    u, v, w = [int(c) for c in input().split()]
    u -= 1
    v -= 1

    if w%2==0:
        if   r[u] != None and r[v] == None:
            r[v] = r[u]
        elif r[u] == None and r[v] != None:
            r[u] = r[v]
        elif r[u] == None and r[v] == None:
            r[u] = r[v] = s
            s+=1
        else:
            same.append((r[u],r[v]))
            
    if w%2==1:
        if r[u] == None:
            r[u] = s
            s+=1
        if r[v] == None:
            r[v] = s
            s+=1
        other.append((r[u],r[v]))
        
color = [{r[0]},set()]

while len(color[0])+len(color[1]) < s:
    for k1, k2 in same:
        for cl in color:
            if k1 in cl: cl.add(k2)
            if k2 in cl: cl.add(k1)

    for k1, k2 in other:
        for cl1, cl2 in ((color[0],color[1]), (color[1],color[0])):
            if k1 in cl1: cl2.add(k2)
            if k2 in cl1: cl2.add(k1)

cmap = [0]*s
for cc in color[1]:
    cmap[cc]=1

for rr in r:
    print(cmap[rr])


Fixed submission:
import sys
sys.setrecursionlimit(100000)

N = int(input())
d = {}
e = [[] for _ in range(N)]
dd = [-1]*N
for _ in range(N-1):
    u, v, w = list(map(int, input().split()))
    e[u-1].append(v-1)
    e[v-1].append(u-1)
    d[(u-1,v-1)]= d[(v-1,u-1)] = w

def dfs(i, _d):
    dd[i] = _d
    for c in e[i]:
        if dd[c]!=-1: continue
        dfs(c, _d+d[(i,c)])

dfs(0,0)
for _dd in dd:
    print(_dd%2)