import sys

sys.setrecursionlimit(20000000)





def dfs(node, distance):

    for next_node, edge_size in G[node]:

        if ans[next_node] == -1:

            ans[next_node] = ((distance+edge_size) % 2)

            dfs(next_node, distance+edge_size)





N = int(input())



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

for i in range(N-1):

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

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

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



ans = [-1]*N

dfs(0, 0)

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

import sys

from sys import stdin

input = stdin.readline

sys.setrecursionlimit(20000000)





def main():

  N = int(eval(input()))

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

  for i in range(N-1):

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

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

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



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

  color[1] = 0

  # S = [1]

  # while len(S):

  #   now = S[-1]

  #   for next_, w in G[now]:

  #     if color[next_] != -1:

  #       continue

  #     S.append(next_)

  #     color[next_] = (w % 2) ^ color[now]

  #     break

  #   else:

  #     S.pop()



  def dfs(now):

    for next_, w in G[now]:

      if color[next_] == -1:

        color[next_] = (w % 2) ^ color[now]

        dfs(next_)

  dfs(1)



  for i in range(1, N+1):

    print((color[i]))





if(__name__ == '__main__'):

  main()

import sys

sys.setrecursionlimit(20000000)


def dfs(node, distance):
    for next_node, edge_size in G[node]:
        if ans[next_node] == -1:
            ans[next_node] = (distance + edge_size) % 2
            dfs(next_node, distance + edge_size)


N = int(input())
G = [[] for i in range(N)]
for i in range(N - 1):
    u, v, w = map(int, input().split())
    G[u - 1].append([v - 1, w])
    G[v - 1].append([u - 1, w])
ans = [-1] * N
dfs(0, 0)
print(*ans, sep="\n")

import sys
from sys import stdin

input = stdin.readline
sys.setrecursionlimit(20000000)


def main():
    N = int(eval(input()))
    G = [[] for _ in range(N + 1)]
    for i in range(N - 1):
        u, v, w = list(map(int, input().split()))
        G[u].append((v, w))
        G[v].append((u, w))
    color = [-1] * (N + 1)
    color[1] = 0
    # S = [1]
    # while len(S):
    #   now = S[-1]
    #   for next_, w in G[now]:
    #     if color[next_] != -1:
    #       continue
    #     S.append(next_)
    #     color[next_] = (w % 2) ^ color[now]
    #     break
    #   else:
    #     S.pop()
    def dfs(now):
        for next_, w in G[now]:
            if color[next_] == -1:
                color[next_] = (w % 2) ^ color[now]
                dfs(next_)

    dfs(1)
    for i in range(1, N + 1):
        print((color[i]))


if __name__ == "__main__":
    main()

+from sys import stdin +input = stdin.readline -def dfs(node, distance): -    for next_node, edge_size in G[node]: -        if ans[next_node] == -1: -            ans[next_node] = (distance + edge_size) % 2 -            dfs(next_node, distance + edge_size) +def main(): +    N = int(eval(input())) +    G = [[] for _ in range(N + 1)] +    for i in range(N - 1): +        u, v, w = list(map(int, input().split())) +        G[u].append((v, w)) +        G[v].append((u, w)) +    color = [-1] * (N + 1) +    color[1] = 0 +    # S = [1] +    # while len(S): +    #   now = S[-1] +    #   for next_, w in G[now]: +    #     if color[next_] != -1: +    #       continue +    #     S.append(next_) +    #     color[next_] = (w % 2) ^ color[now] +    #     break +    #   else: +    #     S.pop() +    def dfs(now): +        for next_, w in G[now]: +            if color[next_] == -1: +                color[next_] = (w % 2) ^ color[now] +                dfs(next_) + +    dfs(1) +    for i in range(1, N + 1): +        print((color[i])) -N = int(input()) -G = [[] for i in range(N)] -for i in range(N - 1): -    u, v, w = map(int, input().split()) -    G[u - 1].append([v - 1, w]) -    G[v - 1].append([u - 1, w]) -ans = [-1] * N -dfs(0, 0) -print(*ans, sep="\n") +if __name__ == "__main__": +    main()