Buggy python submission (verdict: Time Limit Exceeded):
def main():
    import collections
    import sys
    input = sys.stdin.readline
    N = int(input())
    uvw = [map(int, input().split()) for i in range(N-1)]

    G = [[-1]*N for i in range(N)]
    for u, v, w in uvw:
        u -= 1
        v -= 1
        G[u][v] = w
        G[v][u] = w
    q = collections.deque()
    q.append((0, 0))
    s = set(range(1, N))
    ans = [0]*N
    while(q):
        x, a = q.popleft()
        tmp = set()
        for y in s:
            if G[x][y] > 0:
                q.append((y, a+G[x][y]))
                ans[y] = (a+G[x][y]) % 2
                tmp.add(y)
        s -= tmp
    print(*ans, sep="\n")


main()


Fixed submission:
import collections
N = int(input())
d = [0]*N
route = [set() for i in range(N)]
for i in range(N-1):
    u, v, w = map(int, input().split())
    u -= 1
    v -= 1
    route[u].add((v, w))
    route[v].add((u, w))
    d[u] += 1
    d[v] += 1
d = d.index(max(d))
q = collections.deque()
q.append((d, 0))

G = [0]*N

while(q):
    x, l = q.popleft()
    for v, w in route[x]:
        G[v] = w + l
        q.append((v, w+l))
        route[v].remove((x, w))
ans = [0]*N

for i in range(N):
    if i == d:
        continue
    if G[i] % 2 == 1:
        ans[i] = 1
for i in range(N):
    print(ans[i])

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    import collections
    import sys
    input = sys.stdin.readline
    N = int(input())
    uvw = [map(int, input().split()) for i in range(N-1)]

    G = [[-1]*N for i in range(N)]
    for u, v, w in uvw:
        u -= 1
        v -= 1
        G[u][v] = w
        G[v][u] = w
    q = collections.deque()
    q.append((0, 0))
    s = set(range(1, N))
    ans = [0]*N
    while(q):
        x, a = q.popleft()
        tmp = set()
        for y in s:
            if G[x][y] > 0:
                q.append((y, a+G[x][y]))
                ans[y] = (a+G[x][y]) % 2
                tmp.add(y)
        s -= tmp
    print(*ans, sep="\n")
main()


Fixed submission:
import collections
N = int(input())
d = [0]*N
route = [set() for i in range(N)]
for i in range(N-1):
    u, v, w = map(int, input().split())
    u -= 1
    v -= 1
    route[u].add((v, w))
    route[v].add((u, w))
    d[u] += 1
    d[v] += 1
d = d.index(max(d))
q = collections.deque()
q.append((d, 0))

G = [0]*N

while(q):
    x, l = q.popleft()
    for v, w in route[x]:
        G[v] = w + l
        q.append((v, w+l))
        route[v].remove((x, w))
ans = [0]*N

for i in range(N):
    if i == d:
        continue
    if G[i] % 2 == 1:
        ans[i] = 1
for i in range(N):
    print(ans[i])

Buggy python submission (verdict: Time Limit Exceeded):
from scipy.sparse.csgraph import csgraph_from_dense, dijkstra
N = int(input())
d = [0]*N
route = [[10**9]*N for i in range(N)]
for i in range(N-1):
    u, v, w = map(int, input().split())
    u -= 1
    v -= 1
    route[u][v] = w
    route[v][u] = w
    d[u] += 1
    d[v] += 1

g = csgraph_from_dense(route, null_value=10**9)

G = dijkstra(g)
d = d.index(max(d))


ans = [0]*N

for i in range(N):
    if i == d:
        continue
    if G[d][i] % 2 != 0:
        ans[i] = 1
for i in range(N):
    print(ans[i])


Fixed submission:
import collections
N = int(input())
d = [0]*N
route = [set() for i in range(N)]
for i in range(N-1):
    u, v, w = map(int, input().split())
    u -= 1
    v -= 1
    route[u].add((v, w))
    route[v].add((u, w))
    d[u] += 1
    d[v] += 1
d = d.index(max(d))
q = collections.deque()
q.append((d, 0))

G = [0]*N

while(q):
    x, l = q.popleft()
    for v, w in route[x]:
        G[v] = w + l
        q.append((v, w+l))
        route[v].remove((x, w))
ans = [0]*N

for i in range(N):
    if i == d:
        continue
    if G[i] % 2 == 1:
        ans[i] = 1
for i in range(N):
    print(ans[i])