Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
N = int(input())
a = [[0] * (N) for i in range(N)]
for n in range(N-1):
    u,v,w = map(int, input().split())
    a[u-1][v-1] += w
    a[v-1][u-1] += w

dist = [0]*N
st = deque()
push, pop = st.appendleft, st.pop
push(0)
while st:
    i = pop()
    for j in range(N):
        if a[i][j] > 0:
            dist[j] = dist[i] + a[i][j]
            a[i][j], a[j][i] = 0,0
            push(j)


for d in dist:
    if d%2 == 0:
        print(0)
    else:
        print(1)

Fixed submission:
from collections import deque
N = int(input())
G = [[] for i in range(N)]
for i in range(N-1):
    u,v,w = map(int, input().split())
    G[u-1].append((v-1, w))
    G[v-1].append((u-1, w))

st = deque()
push, pop = st.appendleft, st.pop
push(0)
dist = [0]*N
cnt = [0]*N
cnt[0] = 1

while st:
    u = pop()
    for v,w in G[u]:
        if cnt[v] == 1:
            continue
        dist[v] = dist[u] + w
        push(v)
        cnt[v] = 1

for d in dist:
    if d%2 == 0:
        print(0)
    else:
        print(1)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
N = int(input())
st = deque()
push, pop = st.appendleft, st.pop

for n in range(N-1):
    push([int(i) for i in input().split()])

dist = [0]*N
cnt = [0]*N

[u,v,w] = pop()
dist[v-1] = dist[u-1] + w 
cnt[u-1],cnt[v-1] = 1,1
while st:
    [u,v,w] = pop()
    if cnt[u-1] == 1:
        dist[v-1] = dist[u-1] + w 
        cnt[u-1],cnt[v-1] = 1,1
    elif cnt[v-1] == 1:
        dist[u-1] = dist[v-1] + w 
        cnt[u-1],cnt[v-1] = 1,1
    else:
        push([u,v,w])



for d in dist:
    if d%2 == 0:
        print(0)
    else:
        print(1)


Fixed submission:
from collections import deque
N = int(input())
G = [[] for i in range(N)]
for i in range(N-1):
    u,v,w = map(int, input().split())
    G[u-1].append((v-1, w))
    G[v-1].append((u-1, w))

st = deque()
push, pop = st.appendleft, st.pop
push(0)
dist = [0]*N
cnt = [0]*N
cnt[0] = 1

while st:
    u = pop()
    for v,w in G[u]:
        if cnt[v] == 1:
            continue
        dist[v] = dist[u] + w
        push(v)
        cnt[v] = 1

for d in dist:
    if d%2 == 0:
        print(0)
    else:
        print(1)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
N = int(input())
st = deque()
push, pop = st.appendleft, st.pop

for n in range(N-1):
    push([int(i) for i in input().split()])

dist = [0]*N
cnt = [0]*N

[u,v,w] = pop()
dist[v-1] = dist[u-1] + w 
cnt[u-1],cnt[v-1] = 1,1
while st:
    [u,v,w] = pop()
    if cnt[u-1] == 1:
        dist[v-1] = dist[u-1] + w 
        cnt[u-1],cnt[v-1] = 1,1
    elif cnt[v-1] == 1:
        dist[u-1] = dist[v-1] + w 
        cnt[u-1],cnt[v-1] = 1,1
    else:
        push([u,v,w])



for d in dist:
    if d%2 == 0:
        print(0)
    else:
        print(1)


Fixed submission:
from collections import deque
N = int(input())
G = [[] for i in range(N)]
for i in range(N-1):
    u,v,w = map(int, input().split())
    G[u-1].append((v-1, w))
    G[v-1].append((u-1, w))

st = deque()
push, pop = st.appendleft, st.pop
push(0)
dist = [0]*N
cnt = [0]*N
cnt[0] = 1

while st:
    u = pop()
    for v,w in G[u]:
        if cnt[v] == 1:
            continue
        dist[v] = dist[u] + w
        push(v)
        cnt[v] = 1

for d in dist:
    if d%2 == 0:
        print(0)
    else:
        print(1)