Buggy python submission (verdict: Runtime Error):
# -*- coding utf-8 -*-
import numpy as np

MOD = 10 ** 9 + 7

n = int(input())

# graph = [[-1] * n for _ in range(n)]
graph = np.zeros((n, n), dtype=np.int64)
graph -= 1
for _ in range(n - 1):
    u, v, w = map(int, input().split())
    graph[u - 1][v - 1] = w
    graph[v - 1][u - 1] = w

dist = [-1] * n
dist[0] = 0
que = [0]
while len(que) != 0:
    i = que.pop()
    for j in range(n):
        if dist[j] == -1 and graph[i][j] != -1:
            dist[j] = dist[i] + graph[i][j]
            que.append(j)

for d in dist:
    print(d % 2)



Fixed submission:
# -*- coding utf-8 -*-

MOD = 10 ** 9 + 7

n = int(input())

graph = [[] for _ in range(n)]
for _ in range(n - 1):
    u, v, w = map(int, input().split())
    graph[u - 1].append((v - 1, w))
    graph[v - 1].append((u - 1, w))

dist = [-1] * n
dist[0] = 0
que = [0]
while len(que) != 0:
    i = que.pop()
    for j, w in graph[i]:
        if dist[j] == -1:
            dist[j] = dist[i] + w
            que.append(j)

for d in dist:
    print(d % 2)

Buggy python submission (verdict: Runtime Error):
# -*- coding utf-8 -*-
import numpy as np

MOD = 10 ** 9 + 7

n = int(input())

# graph = [[-1] * n for _ in range(n)]
graph = np.zeros((n, n), dtype=np.int)
graph -= 1
for _ in range(n - 1):
    u, v, w = map(int, input().split())
    graph[u - 1][v - 1] = w
    graph[v - 1][u - 1] = w

dist = [-1] * n
dist[0] = 0
que = [0]
while len(que) != 0:
    i = que.pop()
    for j in range(n):
        if dist[j] == -1 and graph[i][j] != -1:
            dist[j] = dist[i] + graph[i][j]
            que.append(j)

for d in dist:
    print(d % 2)



Fixed submission:
# -*- coding utf-8 -*-

MOD = 10 ** 9 + 7

n = int(input())

graph = [[] for _ in range(n)]
for _ in range(n - 1):
    u, v, w = map(int, input().split())
    graph[u - 1].append((v - 1, w))
    graph[v - 1].append((u - 1, w))

dist = [-1] * n
dist[0] = 0
que = [0]
while len(que) != 0:
    i = que.pop()
    for j, w in graph[i]:
        if dist[j] == -1:
            dist[j] = dist[i] + w
            que.append(j)

for d in dist:
    print(d % 2)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding utf-8 -*-
import copy

MOD = 10 ** 9 + 7

n = int(input())

graph = [[-1] * n for _ in range(n)]
for _ in range(n - 1):
    u, v, w = map(int, input().split())
    graph[u - 1][v - 1] = w
    graph[v - 1][u - 1] = w

dist = [-1] * n
dist[0] = 0
que = [0]
while len(que) != 0:
    i = que.pop()
    for j in range(n):
        if dist[j] == -1 and graph[i][j] != -1:
            dist[j] = dist[i] + graph[i][j]
            que.append(j)

for d in dist:
    print(d % 2)



Fixed submission:
# -*- coding utf-8 -*-

MOD = 10 ** 9 + 7

n = int(input())

graph = [[] for _ in range(n)]
for _ in range(n - 1):
    u, v, w = map(int, input().split())
    graph[u - 1].append((v - 1, w))
    graph[v - 1].append((u - 1, w))

dist = [-1] * n
dist[0] = 0
que = [0]
while len(que) != 0:
    i = que.pop()
    for j, w in graph[i]:
        if dist[j] == -1:
            dist[j] = dist[i] + w
            que.append(j)

for d in dist:
    print(d % 2)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding utf-8 -*-
import copy

MOD = 10 ** 9 + 7

n = int(input())

graph = [[-1] * n for _ in range(n)]
for _ in range(n - 1):
    u, v, w = map(int, input().split())
    graph[u - 1][v - 1] = w
    graph[v - 1][u - 1] = w

root = 0
dist = [-1] * (n)
new = {0}
not_yet = set(list(range(n)))
not_yet -= {0}
while len(new) != 0:
    next_new = set()
    for i in new:
        for j in not_yet:
            if graph[i][j] != -1:
                dist[j] = dist[i] + graph[i][j]
                next_new.add(j)
    not_yet -= next_new
    new = next_new

for d in dist:
    print(d % 2)



Fixed submission:
# -*- coding utf-8 -*-

MOD = 10 ** 9 + 7

n = int(input())

graph = [[] for _ in range(n)]
for _ in range(n - 1):
    u, v, w = map(int, input().split())
    graph[u - 1].append((v - 1, w))
    graph[v - 1].append((u - 1, w))

dist = [-1] * n
dist[0] = 0
que = [0]
while len(que) != 0:
    i = que.pop()
    for j, w in graph[i]:
        if dist[j] == -1:
            dist[j] = dist[i] + w
            que.append(j)

for d in dist:
    print(d % 2)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding utf-8 -*-
import copy

MOD = 10 ** 9 + 7

n = int(input())
uvw_n = [list(map(int, input().split())) for _ in range(n - 1)]

graph = [[-1] * n for _ in range(n)]
for u, v, w in uvw_n:
    graph[u - 1][v - 1] = w
    graph[v - 1][u - 1] = w

root = 0
dist = [-1] * (n)
new = {0}
not_yet = set(list(range(n)))
not_yet -= {0}
while len(new) != 0:
    next_new = set()
    for i in new:
        for j in not_yet:
            if graph[i][j] != -1:
                dist[j] = dist[i] + graph[i][j]
                next_new.add(j)
    not_yet -= next_new
    new = next_new

for d in dist:
    print(d % 2)



Fixed submission:
# -*- coding utf-8 -*-

MOD = 10 ** 9 + 7

n = int(input())

graph = [[] for _ in range(n)]
for _ in range(n - 1):
    u, v, w = map(int, input().split())
    graph[u - 1].append((v - 1, w))
    graph[v - 1].append((u - 1, w))

dist = [-1] * n
dist[0] = 0
que = [0]
while len(que) != 0:
    i = que.pop()
    for j, w in graph[i]:
        if dist[j] == -1:
            dist[j] = dist[i] + w
            que.append(j)

for d in dist:
    print(d % 2)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding utf-8 -*-
import copy

MOD = 10 ** 9 + 7

n = int(input())
uvw_n = [list(map(int, input().split())) for _ in range(n - 1)]

graph = [[-1] * n for _ in range(n)]
for u, v, w in uvw_n:
    graph[u - 1][v - 1] = w
    graph[v - 1][u - 1] = w

root = 0
dist = [-1] * (n)
new = {0}
not_yet = set(list(range(n)))
not_yet -= {0}
while len(new) != 0:
    next_new = set()
    for i in new:
        for j in not_yet:
            if graph[i][j] != -1:
                dist[j] = dist[i] + graph[i][j]
                next_new.add(j)
    not_yet -= next_new
    new = next_new

for d in dist:
    print(d % 2)



Fixed submission:
# -*- coding utf-8 -*-

MOD = 10 ** 9 + 7

n = int(input())

graph = [[] for _ in range(n)]
for _ in range(n - 1):
    u, v, w = map(int, input().split())
    graph[u - 1].append((v - 1, w))
    graph[v - 1].append((u - 1, w))

dist = [-1] * n
dist[0] = 0
que = [0]
while len(que) != 0:
    i = que.pop()
    for j, w in graph[i]:
        if dist[j] == -1:
            dist[j] = dist[i] + w
            que.append(j)

for d in dist:
    print(d % 2)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding utf-8 -*-
import copy

MOD = 10 ** 9 + 7

n = int(input())
uvw_n = [list(map(int, input().split())) for _ in range(n - 1)]

graph = [[-1] * n for _ in range(n)]
for u, v, w in uvw_n:
    graph[u - 1][v - 1] = w
    graph[v - 1][u - 1] = w

# print(graph)

root = 0
dist = [-1] * (n)
new = {0}
while len(new) != 0:
    next_new = set()
    for i in new:
        for j in range(n):
            if dist[j] == -1 and graph[i][j] != -1:
                dist[j] = dist[i] + graph[i][j]
                next_new.add(j)
    # print(next_new)
    new = next_new

for d in dist:
    print(d % 2)



Fixed submission:
# -*- coding utf-8 -*-

MOD = 10 ** 9 + 7

n = int(input())

graph = [[] for _ in range(n)]
for _ in range(n - 1):
    u, v, w = map(int, input().split())
    graph[u - 1].append((v - 1, w))
    graph[v - 1].append((u - 1, w))

dist = [-1] * n
dist[0] = 0
que = [0]
while len(que) != 0:
    i = que.pop()
    for j, w in graph[i]:
        if dist[j] == -1:
            dist[j] = dist[i] + w
            que.append(j)

for d in dist:
    print(d % 2)