import sys

readline = sys.stdin.readline



# スタートを0で塗り、行先が奇数であれば違う色で塗る、を繰り返せばよい

N = int(readline())

G = [[] for i in range(N)]



for i in range(N - 1):

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

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

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



ans = [-1] * N



stack = []

# 頂点, 色

stack.append([0,0])

while stack:

  v,color = stack.pop()

  if ans[v] != -1:

    continue

  ans[v] = color

  for child in G[v]:

    col = color

    if child[1] % 2 == 1:

      col ^= 1

    stack.append([child[0], col])



for a in ans:

  print(a)
import sys

readline = sys.stdin.readline



N = int(readline())

G = [[] for i in range(N)]



for i in range(N - 1):

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

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

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

  

color = [-1] * N

stack = []

stack.append([0, -1, 0])

while stack:

  v,parent,cost = stack.pop()

  color[v] = cost

  for child in G[v]:

    if child[0] == parent:

      continue

    stack.append([child[0], v, (cost + child[1]) % 2])



for c in color:

  print(c)
import sys

readline = sys.stdin.readline
# スタートを0で塗り、行先が奇数であれば違う色で塗る、を繰り返せばよい
N = int(readline())
G = [[] for i in range(N)]
for i in range(N - 1):
    u, v, w = list(map(int, readline().split()))
    G[u - 1].append([v - 1, w])
    G[v - 1].append([u - 1, w])
ans = [-1] * N
stack = []
# 頂点, 色
stack.append([0, 0])
while stack:
    v, color = stack.pop()
    if ans[v] != -1:
        continue
    ans[v] = color
    for child in G[v]:
        col = color
        if child[1] % 2 == 1:
            col ^= 1
        stack.append([child[0], col])
for a in ans:
    print(a)

import sys

readline = sys.stdin.readline
N = int(readline())
G = [[] for i in range(N)]
for i in range(N - 1):
    u, v, w = list(map(int, readline().split()))
    G[u - 1].append((v - 1, w))
    G[v - 1].append((u - 1, w))
color = [-1] * N
stack = []
stack.append([0, -1, 0])
while stack:
    v, parent, cost = stack.pop()
    color[v] = cost
    for child in G[v]:
        if child[0] == parent:
            continue
        stack.append([child[0], v, (cost + child[1]) % 2])
for c in color:
    print(c)

-# スタートを0で塗り、行先が奇数であれば違う色で塗る、を繰り返せばよい -    G[u - 1].append([v - 1, w]) -    G[v - 1].append([u - 1, w]) -ans = [-1] * N +    G[u - 1].append((v - 1, w)) +    G[v - 1].append((u - 1, w)) +color = [-1] * N -# 頂点, 色 -stack.append([0, 0]) +stack.append([0, -1, 0]) -    v, color = stack.pop() -    if ans[v] != -1: -        continue -    ans[v] = color +    v, parent, cost = stack.pop() +    color[v] = cost -        col = color -        if child[1] % 2 == 1: -            col ^= 1 -        stack.append([child[0], col]) -for a in ans: -    print(a) +        if child[0] == parent: +            continue +        stack.append([child[0], v, (cost + child[1]) % 2]) +for c in color: +    print(c)