N=int(eval(input()))

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

for i in range(N-1):

  a,b,w=list(map(int,input().split()))

  a,b,w=a-1,b-1,w%2

  E[a].append([b,w])

  E[b].append([a,w])

  

stack=[]

C=[None]*N

# 番号,色,親

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

while stack:

  node=stack.pop()

  v=node[0]

  color=node[1]

  parent=node[2]

  C[v]=color

  children=E[v]

  for child in children:

    child_v=child[0]

    child_w=child[1]

    if child_v==parent:

      continue

    child_color=abs(child_w-color)

    stack.append([child_v,child_color,v])



for ans in C:

  print(ans)
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)
N = int(eval(input()))
E = [[] for i in range(N)]
for i in range(N - 1):
    a, b, w = list(map(int, input().split()))
    a, b, w = a - 1, b - 1, w % 2
    E[a].append([b, w])
    E[b].append([a, w])
stack = []
C = [None] * N
# 番号,色,親
stack.append([0, 0, -1])
while stack:
    node = stack.pop()
    v = node[0]
    color = node[1]
    parent = node[2]
    C[v] = color
    children = E[v]
    for child in children:
        child_v = child[0]
        child_w = child[1]
        if child_v == parent:
            continue
        child_color = abs(child_w - color)
        stack.append([child_v, child_color, v])
for ans in C:
    print(ans)

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)

-N = int(eval(input())) -E = [[] for i in range(N)] +import sys + +readline = sys.stdin.readline +# スタートを0で塗り、行先が奇数であれば違う色で塗る、を繰り返せばよい +N = int(readline()) +G = [[] for i in range(N)] -    a, b, w = list(map(int, input().split())) -    a, b, w = a - 1, b - 1, w % 2 -    E[a].append([b, w]) -    E[b].append([a, w]) +    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 -C = [None] * N -# 番号,色,親 -stack.append([0, 0, -1]) +# 頂点, 色 +stack.append([0, 0]) -    node = stack.pop() -    v = node[0] -    color = node[1] -    parent = node[2] -    C[v] = color -    children = E[v] -    for child in children: -        child_v = child[0] -        child_w = child[1] -        if child_v == parent: -            continue -        child_color = abs(child_w - color) -        stack.append([child_v, child_color, v]) -for ans in C: -    print(ans) +    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)