n = int(eval(input()))

g =[[] for _ in range(n)]

for i in range(n-1):

  u,v,w = list(map(int,input().split()))

  g[u-1].append((v-1,w))

  g[v-1].append((u-1,w))

distance = [-1]*n

distance[0] = 0

q = [0]

while q:

  p = q.pop()

  for a,b in g[p]:

    if distance[a] == -1:

      distance[a] = distance[p]+b

      q.append(a)

for i in range(n):

  print(((distance[i])%2))
import sys

import copy

sys.setrecursionlimit(10**7)

def dfs(graph,v,dist_mod):

    color[v] = dist_mod

    for next_v,dist in graph[v]:

        if color[next_v] != -1:

            continue

        dfs(graph,next_v,(dist_mod+dist)%2)

n = int(eval(input()))

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

g = [[] for _ in range(n)]

color = [-1]*n

for i in range(n-1):

    g[uvw[i][0]-1].append([uvw[i][1]-1,uvw[i][2]])

    g[uvw[i][1]-1].append([uvw[i][0]-1,uvw[i][2]])

dfs(g,0,0)

for i in range(n):

    print((color[i]))
n = int(eval(input()))
g = [[] for _ in range(n)]
for i in range(n - 1):
    u, v, w = list(map(int, input().split()))
    g[u - 1].append((v - 1, w))
    g[v - 1].append((u - 1, w))
distance = [-1] * n
distance[0] = 0
q = [0]
while q:
    p = q.pop()
    for a, b in g[p]:
        if distance[a] == -1:
            distance[a] = distance[p] + b
            q.append(a)
for i in range(n):
    print(((distance[i]) % 2))

import sys
import copy

sys.setrecursionlimit(10**7)


def dfs(graph, v, dist_mod):
    color[v] = dist_mod
    for next_v, dist in graph[v]:
        if color[next_v] != -1:
            continue
        dfs(graph, next_v, (dist_mod + dist) % 2)


n = int(eval(input()))
uvw = [list(map(int, input().split())) for _ in range(n - 1)]
g = [[] for _ in range(n)]
color = [-1] * n
for i in range(n - 1):
    g[uvw[i][0] - 1].append([uvw[i][1] - 1, uvw[i][2]])
    g[uvw[i][1] - 1].append([uvw[i][0] - 1, uvw[i][2]])
dfs(g, 0, 0)
for i in range(n):
    print((color[i]))

+import sys +import copy + +sys.setrecursionlimit(10**7) + + +def dfs(graph, v, dist_mod): +    color[v] = dist_mod +    for next_v, dist in graph[v]: +        if color[next_v] != -1: +            continue +        dfs(graph, next_v, (dist_mod + dist) % 2) + + +uvw = [list(map(int, input().split())) for _ in range(n - 1)] +color = [-1] * n -    u, v, w = list(map(int, input().split())) -    g[u - 1].append((v - 1, w)) -    g[v - 1].append((u - 1, w)) -distance = [-1] * n -distance[0] = 0 -q = [0] -while q: -    p = q.pop() -    for a, b in g[p]: -        if distance[a] == -1: -            distance[a] = distance[p] + b -            q.append(a) +    g[uvw[i][0] - 1].append([uvw[i][1] - 1, uvw[i][2]]) +    g[uvw[i][1] - 1].append([uvw[i][0] - 1, uvw[i][2]]) +dfs(g, 0, 0) -    print(((distance[i]) % 2)) +    print((color[i]))