from collections import deque

n = int(input())



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



for i in range(n-1):

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

  u, v  = u-1, v-1

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

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



c = [-1]*n

c[0] = 0



queue = deque([0])



while queue:

  x = queue.popleft()

  for x_, w_ in g[x]:

    if c[x_] == -1:

      if w_%2 == 0:

        c[x_] = c[x]

      else:

        c[x_] = 1-c[x]

      queue.append(x_)

    else:

      continue



print(*c, sep='\n')

  



import sys

#sys.setrecursionlimit(10**6)

input = sys.stdin.readline



n = int(eval(input()))

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

for i in range(n-1):

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

    u, v = u-1, v-1

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

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



from collections import deque

s = deque()

s.append(0)

visit = [-1]*n

visit[0] = 0

while s:

    u = s.pop()

    for v, w in g[u]:

        if visit[v] == -1:

            if w%2 == 0:

                visit[v] = visit[u]

            else:

                visit[v] = 1 - visit[u]

            s.append(v)

for i in range(n):

    print((visit[i]))
from collections import deque

n = int(input())
g = [[] for i in range(n)]
for i in range(n - 1):
    u, v, w = map(int, input().split())
    u, v = u - 1, v - 1
    g[u].append([v, w])
    g[v].append([u, w])
c = [-1] * n
c[0] = 0
queue = deque([0])
while queue:
    x = queue.popleft()
    for x_, w_ in g[x]:
        if c[x_] == -1:
            if w_ % 2 == 0:
                c[x_] = c[x]
            else:
                c[x_] = 1 - c[x]
            queue.append(x_)
        else:
            continue
print(*c, sep="\n")

import sys

# sys.setrecursionlimit(10**6)
input = sys.stdin.readline
n = int(eval(input()))
g = [[] for _ in range(n)]
for i in range(n - 1):
    u, v, w = list(map(int, input().split()))
    u, v = u - 1, v - 1
    g[u].append((v, w))
    g[v].append((u, w))
from collections import deque

s = deque()
s.append(0)
visit = [-1] * n
visit[0] = 0
while s:
    u = s.pop()
    for v, w in g[u]:
        if visit[v] == -1:
            if w % 2 == 0:
                visit[v] = visit[u]
            else:
                visit[v] = 1 - visit[u]
            s.append(v)
for i in range(n):
    print((visit[i]))

+import sys + +# sys.setrecursionlimit(10**6) +input = sys.stdin.readline +n = int(eval(input())) +g = [[] for _ in range(n)] +for i in range(n - 1): +    u, v, w = list(map(int, input().split())) +    u, v = u - 1, v - 1 +    g[u].append((v, w)) +    g[v].append((u, w)) -n = int(input()) -g = [[] for i in range(n)] -for i in range(n - 1): -    u, v, w = map(int, input().split()) -    u, v = u - 1, v - 1 -    g[u].append([v, w]) -    g[v].append([u, w]) -c = [-1] * n -c[0] = 0 -queue = deque([0]) -while queue: -    x = queue.popleft() -    for x_, w_ in g[x]: -        if c[x_] == -1: -            if w_ % 2 == 0: -                c[x_] = c[x] +s = deque() +s.append(0) +visit = [-1] * n +visit[0] = 0 +while s: +    u = s.pop() +    for v, w in g[u]: +        if visit[v] == -1: +            if w % 2 == 0: +                visit[v] = visit[u] -                c[x_] = 1 - c[x] -            queue.append(x_) -        else: -            continue -print(*c, sep="\n") +                visit[v] = 1 - visit[u] +            s.append(v) +for i in range(n): +    print((visit[i]))