import sys

sys.setrecursionlimit(10 ** 7)



N = int(input())

G = [[] for _ in range(N+1)]



for _ in range(N-1):

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

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

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



res = [0]*(N+1)

# 現在頂点v を c に塗る。p は v の親

def dfs(v, p, c):

  res[v] = c

  for e, w in G[v]:   

    if e == p:

      continue    

    if w&1:

      # エッジの重みが奇数だったら、次のノードは異色 1-c で塗る

      dfs(e, v, 1-c)

    else:

      #エッジの重みが偶数だったら、次のノードも同色 c で塗る

      dfs(e, v, c)

# res:start[1:] even:cor==0   

dfs(1, 0, 0)      

[print(r) for r in res[1:]]

import sys

from collections import deque

sys.setrecursionlimit(10 ** 7)



N = int(input())

G = [[] for _ in range(N+1)]



for _ in range(N-1):

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

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

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



deq = deque()

deq.append(1)

res = [-1]*(N+1)

res[1] = 0



while deq:

  x = deq.popleft()

  for e, w in G[x]:

    if res[e] == -1:

      res[e] = (res[x]+w)%2

      deq.append(e)

[print(r) for r in res[1:]]

import sys

sys.setrecursionlimit(10**7)
N = int(input())
G = [[] for _ in range(N + 1)]
for _ in range(N - 1):
    v, u, w = map(int, input().split())
    G[v].append((u, w))
    G[u].append((v, w))
res = [0] * (N + 1)
# 現在頂点v を c に塗る。p は v の親
def dfs(v, p, c):
    res[v] = c
    for e, w in G[v]:
        if e == p:
            continue
        if w & 1:
            # エッジの重みが奇数だったら、次のノードは異色 1-c で塗る
            dfs(e, v, 1 - c)
        else:
            # エッジの重みが偶数だったら、次のノードも同色 c で塗る
            dfs(e, v, c)


# res:start[1:] even:cor==0
dfs(1, 0, 0)
[print(r) for r in res[1:]]

import sys
from collections import deque

sys.setrecursionlimit(10**7)
N = int(input())
G = [[] for _ in range(N + 1)]
for _ in range(N - 1):
    v, u, w = map(int, input().split())
    G[v].append((u, w))
    G[u].append((v, w))
deq = deque()
deq.append(1)
res = [-1] * (N + 1)
res[1] = 0
while deq:
    x = deq.popleft()
    for e, w in G[x]:
        if res[e] == -1:
            res[e] = (res[x] + w) % 2
            deq.append(e)
[print(r) for r in res[1:]]

+from collections import deque -res = [0] * (N + 1) -# 現在頂点v を c に塗る。p は v の親 -def dfs(v, p, c): -    res[v] = c -    for e, w in G[v]: -        if e == p: -            continue -        if w & 1: -            # エッジの重みが奇数だったら、次のノードは異色 1-c で塗る -            dfs(e, v, 1 - c) -        else: -            # エッジの重みが偶数だったら、次のノードも同色 c で塗る -            dfs(e, v, c) - - -# res:start[1:] even:cor==0 -dfs(1, 0, 0) +deq = deque() +deq.append(1) +res = [-1] * (N + 1) +res[1] = 0 +while deq: +    x = deq.popleft() +    for e, w in G[x]: +        if res[e] == -1: +            res[e] = (res[x] + w) % 2 +            deq.append(e)