Buggy python submission (verdict: Time Limit Exceeded):
# D - Even Relation

# 木なのでノードAB間の辺を辿ればそれがAB間の最短経路となる

from collections import deque

N = int(input())

dist = [[0]*N for _ in range(N)]
neighbor = [[] for _ in range(N)]

for _ in range(N-1):
    u, v, w = map(int, input().split())
    dist[u-1][v-1] = w%2 + 2
    dist[v-1][u-1] = w%2 + 2
    neighbor[u-1].append(v-1)
    neighbor[v-1].append(u-1)

d = deque([0])
color = [0] + [-1]*(N-1)

while d:
    current_point = d.popleft()
    for next_point in neighbor[current_point]:
        if color[next_point] != -1:
            continue
        else:
            color[next_point] = (color[current_point] + dist[current_point][next_point]) % 2
            d.append(next_point)

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

Fixed submission:
# D - Even Relation

# 木なのでノードAB間の辺を辿ればそれがAB間の最短経路となる
# 全ての｢辺｣についてループする

from collections import deque

N = int(input())

edge = [[] for _ in range(N)]

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

color = [0] + [-1]*(N-1)
d = deque([0])

while d:
    current_point = d.pop()
    for current_edge in edge[current_point]:
        if color[current_edge[0]] == -1:
            color[current_edge[0]] = (color[current_point] + current_edge[1]) % 2
            d.append(current_edge[0])

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

Buggy python submission (verdict: Time Limit Exceeded):
# D - Even Relation

# 木なのでノードAB間の辺を辿ればそれがAB間の最短経路となる

from collections import deque

N = int(input())

dist = [[0]*N for _ in range(N)]
neighbor = [[] for _ in range(N)]

for _ in range(N-1):
    u, v, w = map(int, input().split())
    dist[u-1][v-1] = w%2 + 2
    dist[v-1][u-1] = w%2 + 2
    neighbor[u-1].append(v-1)
    neighbor[v-1].append(u-1)

d = deque([0])
color = [0] + [-1]*(N-1)

while color.count(-1) > 0:
    current_point = d.popleft()
    for next_point in neighbor[current_point]:
        if color[next_point] != -1:
            continue
        else:
            color[next_point] = (color[current_point] + dist[current_point][next_point]) % 2
            d.append(next_point)

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

Fixed submission:
# D - Even Relation

# 木なのでノードAB間の辺を辿ればそれがAB間の最短経路となる
# 全ての｢辺｣についてループする

from collections import deque

N = int(input())

edge = [[] for _ in range(N)]

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

color = [0] + [-1]*(N-1)
d = deque([0])

while d:
    current_point = d.pop()
    for current_edge in edge[current_point]:
        if color[current_edge[0]] == -1:
            color[current_edge[0]] = (color[current_point] + current_edge[1]) % 2
            d.append(current_edge[0])

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

Buggy python submission (verdict: Time Limit Exceeded):
# D - Even Relation

# 木なのでノードAB間の辺を辿ればそれがAB間の最短経路となる

from collections import deque

N = int(input())

dist = [[0]*N for _ in range(N)]
neighbor = [[] for _ in range(N)]

for _ in range(N-1):
    u, v, w = map(int, input().split())
    dist[u-1][v-1] = w%2 + 2
    dist[v-1][u-1] = w%2 + 2
    neighbor[u-1].append(v-1)
    neighbor[v-1].append(u-1)

d = deque([0])
color = [0] + [-1]*(N-1)

while d:
    current_point = d.popleft()
    for next_point in neighbor[current_point]:
        if color[next_point] != -1:
            continue
        else:
            color[next_point] = (color[current_point] + dist[current_point][next_point]) % 2
            d.append(next_point)

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

Fixed submission:
# D - Even Relation

# 木なのでノードAB間の辺を辿ればそれがAB間の最短経路となる
# 全ての｢辺｣についてループする

from collections import deque

N = int(input())

edge = [[] for _ in range(N)]

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

color = [0] + [-1]*(N-1)
d = deque([0])

while d:
    current_point = d.pop()
    for current_edge in edge[current_point]:
        if color[current_edge[0]] == -1:
            color[current_edge[0]] = (color[current_point] + current_edge[1]) % 2
            d.append(current_edge[0])

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

Buggy python submission (verdict: Time Limit Exceeded):
# D - Even Relation

# ある頂点からの距離の偶奇が一致する点を同じ色で塗る

from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import dijkstra

N = int(input())

neighbor = [[0]*N for _ in range(N)]

for _ in range(N-1):
    u, v, w = map(int, input().split())
    neighbor[u-1][v-1] = w%2 + 2
    neighbor[v-1][u-1] = w%2 + 2

neighbor = csr_matrix(neighbor)
dist_from_0 = dijkstra(neighbor, indices = 0)

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

Fixed submission:
# D - Even Relation

# 木なのでノードAB間の辺を辿ればそれがAB間の最短経路となる
# 全ての｢辺｣についてループする

from collections import deque

N = int(input())

edge = [[] for _ in range(N)]

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

color = [0] + [-1]*(N-1)
d = deque([0])

while d:
    current_point = d.pop()
    for current_edge in edge[current_point]:
        if color[current_edge[0]] == -1:
            color[current_edge[0]] = (color[current_point] + current_edge[1]) % 2
            d.append(current_edge[0])

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

Buggy python submission (verdict: Runtime Error):
# D - Even Relation

# ある頂点からの距離の偶奇が一致する点を同じ色で塗る
# scipy.sparse.csgraphのdijkstraではTLEになる模様

from scipy.sparse.csgraph import dijkstra
import sys

N = int(input())

neighbor = [[0]*N for _ in range(N)]

for _ in range(N-1):
    u, v, w = map(int, input().split())
    neighbor[u-1][v-1] = w%2 + 2
    neighbor[v-1][u-1] = w%2 + 2

dist_from_0 = dijkstra(neighbor, indices = 0)

a = 1//0

# for i in range(N):
#     print(0 if dist_from_0[i]%2 == 0 else 1)


Fixed submission:
# D - Even Relation

# 木なのでノードAB間の辺を辿ればそれがAB間の最短経路となる
# 全ての｢辺｣についてループする

from collections import deque

N = int(input())

edge = [[] for _ in range(N)]

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

color = [0] + [-1]*(N-1)
d = deque([0])

while d:
    current_point = d.pop()
    for current_edge in edge[current_point]:
        if color[current_edge[0]] == -1:
            color[current_edge[0]] = (color[current_point] + current_edge[1]) % 2
            d.append(current_edge[0])

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

Buggy python submission (verdict: Time Limit Exceeded):
# D - Even Relation

# ある頂点からの距離の偶奇が一致する点を同じ色で塗る

from scipy.sparse.csgraph import dijkstra

N = int(input())

neighbor = [[0]*N for _ in range(N)]

for _ in range(N-1):
    u, v, w = map(int, input().split())
    neighbor[u-1][v-1] = w%2 + 2
    neighbor[v-1][u-1] = w%2 + 2

dist_from_0 = dijkstra(neighbor, indices = 0)

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

Fixed submission:
# D - Even Relation

# 木なのでノードAB間の辺を辿ればそれがAB間の最短経路となる
# 全ての｢辺｣についてループする

from collections import deque

N = int(input())

edge = [[] for _ in range(N)]

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

color = [0] + [-1]*(N-1)
d = deque([0])

while d:
    current_point = d.pop()
    for current_edge in edge[current_point]:
        if color[current_edge[0]] == -1:
            color[current_edge[0]] = (color[current_point] + current_edge[1]) % 2
            d.append(current_edge[0])

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

Buggy python submission (verdict: Runtime Error):
# D - Even Relation

# ある頂点からの距離の偶奇が一致する点を同じ色で塗る

from scipy.sparse.csgraph import dijkstra

N = int(input())

neighbor = [[0]*N for _ in range(N)]

for _ in range(N-1):
    u, v, w = map(int, input().split())
    neighbor[u-1][v-1] = w%2 + 2
    neighbor[v-1][u-1] = w%2 + 2

dist_from_0 = dijkstra(neighbor, indices = 0)

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

Fixed submission:
# D - Even Relation

# 木なのでノードAB間の辺を辿ればそれがAB間の最短経路となる
# 全ての｢辺｣についてループする

from collections import deque

N = int(input())

edge = [[] for _ in range(N)]

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

color = [0] + [-1]*(N-1)
d = deque([0])

while d:
    current_point = d.pop()
    for current_edge in edge[current_point]:
        if color[current_edge[0]] == -1:
            color[current_edge[0]] = (color[current_point] + current_edge[1]) % 2
            d.append(current_edge[0])

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

Buggy python submission (verdict: Time Limit Exceeded):
# D - Even Relation

# ある頂点からの距離の偶奇が一致する点を同じ色で塗る

from scipy.sparse.csgraph import dijkstra

N = int(input())

neighbor = [[0]*N for _ in range(N)]

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

dist_from_0 = dijkstra(neighbor, indices = 0)

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

Fixed submission:
# D - Even Relation

# 木なのでノードAB間の辺を辿ればそれがAB間の最短経路となる
# 全ての｢辺｣についてループする

from collections import deque

N = int(input())

edge = [[] for _ in range(N)]

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

color = [0] + [-1]*(N-1)
d = deque([0])

while d:
    current_point = d.pop()
    for current_edge in edge[current_point]:
        if color[current_edge[0]] == -1:
            color[current_edge[0]] = (color[current_point] + current_edge[1]) % 2
            d.append(current_edge[0])

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