import sys

sys.setrecursionlimit(100000)



N = int(eval(input()))

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

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

for w in W:

    nodes[w[0]].append((w[1], w[2]))

    nodes[w[1]].append((w[0], w[2]))

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

ans[1] = 0

def search(num, root, dis):

    for node in nodes[num]:

        sum_d = dis

        if node[0] != root:

            idx = node[0]

            sum_d += node[1]%2

            if sum_d%2 != 0:

                ans[idx] = 1

            else:

                ans[idx] = 0

            search(idx, num, sum_d)



search(1, 0, 0)

for answer in ans[1:]:

    print(answer)

from collections import deque



N = int(eval(input()))

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

for _ in range(N-1):

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

  d_list[a].append((b, a, c))

  d_list[b].append((a, b, c))

que = deque([])

for v in d_list[1]:

  que.append(v)

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

ans[1] = 0

while len(que) > 0:

  v = que.popleft()

  ans[v[0]] = (ans[v[1]]+v[2])%2

  for n in d_list[v[0]]:

    if ans[n[0]] == -1:

      que.append(n)

for a in ans[1:]:

  print(a)
import sys

sys.setrecursionlimit(100000)
N = int(eval(input()))
W = [list(map(int, input().split())) for _ in range(N - 1)]
nodes = [[] for _ in range(N + 1)]
for w in W:
    nodes[w[0]].append((w[1], w[2]))
    nodes[w[1]].append((w[0], w[2]))
ans = [-1] * (N + 1)
ans[1] = 0


def search(num, root, dis):
    for node in nodes[num]:
        sum_d = dis
        if node[0] != root:
            idx = node[0]
            sum_d += node[1] % 2
            if sum_d % 2 != 0:
                ans[idx] = 1
            else:
                ans[idx] = 0
            search(idx, num, sum_d)


search(1, 0, 0)
for answer in ans[1:]:
    print(answer)

from collections import deque

N = int(eval(input()))
d_list = [[] for _ in range(N + 1)]
for _ in range(N - 1):
    a, b, c = list(map(int, input().split()))
    d_list[a].append((b, a, c))
    d_list[b].append((a, b, c))
que = deque([])
for v in d_list[1]:
    que.append(v)
ans = [-1] * (N + 1)
ans[1] = 0
while len(que) > 0:
    v = que.popleft()
    ans[v[0]] = (ans[v[1]] + v[2]) % 2
    for n in d_list[v[0]]:
        if ans[n[0]] == -1:
            que.append(n)
for a in ans[1:]:
    print(a)

-import sys +from collections import deque -sys.setrecursionlimit(100000) -W = [list(map(int, input().split())) for _ in range(N - 1)] -nodes = [[] for _ in range(N + 1)] -for w in W: -    nodes[w[0]].append((w[1], w[2])) -    nodes[w[1]].append((w[0], w[2])) +d_list = [[] for _ in range(N + 1)] +for _ in range(N - 1): +    a, b, c = list(map(int, input().split())) +    d_list[a].append((b, a, c)) +    d_list[b].append((a, b, c)) +que = deque([]) +for v in d_list[1]: +    que.append(v) - - -def search(num, root, dis): -    for node in nodes[num]: -        sum_d = dis -        if node[0] != root: -            idx = node[0] -            sum_d += node[1] % 2 -            if sum_d % 2 != 0: -                ans[idx] = 1 -            else: -                ans[idx] = 0 -            search(idx, num, sum_d) - - -search(1, 0, 0) -for answer in ans[1:]: -    print(answer) +while len(que) > 0: +    v = que.popleft() +    ans[v[0]] = (ans[v[1]] + v[2]) % 2 +    for n in d_list[v[0]]: +        if ans[n[0]] == -1: +            que.append(n) +for a in ans[1:]: +    print(a)