from collections import deque

from collections import Counter

from itertools import product, permutations,combinations

from operator import itemgetter

from heapq import heappop, heappush

import math

import sys

input = sys.stdin.readline

#文字列のときはうまく行かないのでコメントアウトすること

sys.setrecursionlimit(2147483647)



def main():

  N = int(eval(input()))

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

  C = [-1] * N

  C[0] = 0

  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))

  def dfs(now):

    for ne_xt, w in G[now]:

      if C[ne_xt]==-1:

        C[ne_xt]=(C[now]+w)%2

        dfs(ne_xt)

  dfs(0)

  for i in range(N):

    print((C[i]))

  

  

if __name__ == '__main__':

  main()
import sys

from collections import deque

readline = sys.stdin.buffer.readline

sys.setrecursionlimit(10 ** 8)

INF = float('inf')

MOD = 10 ** 9 + 7



def main():

    N = int(readline())

    tree = [[] for _ in range(N)]

    for i in range(N-1):

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

        u, v = u-1, v-1

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

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

    color = [-1]*N

    color[0]=0



    que = deque([0])

    while que:

        index = que.popleft()

        for next_, weight in tree[index]:

            if color[next_]==-1:

                if weight%2==0:

                    color[next_] = color[index]

                else:

                    color[next_] = color[index]^1

                que.append(next_)

    for c in color:

        print(c)





if __name__ == '__main__':

    main()
from collections import deque
from collections import Counter
from itertools import product, permutations, combinations
from operator import itemgetter
from heapq import heappop, heappush
import math
import sys

input = sys.stdin.readline
# 文字列のときはうまく行かないのでコメントアウトすること
sys.setrecursionlimit(2147483647)


def main():
    N = int(eval(input()))
    G = [[] for i in range(N)]
    C = [-1] * N
    C[0] = 0
    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))

    def dfs(now):
        for ne_xt, w in G[now]:
            if C[ne_xt] == -1:
                C[ne_xt] = (C[now] + w) % 2
                dfs(ne_xt)

    dfs(0)
    for i in range(N):
        print((C[i]))


if __name__ == "__main__":
    main()

import sys
from collections import deque

readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10**8)
INF = float("inf")
MOD = 10**9 + 7


def main():
    N = int(readline())
    tree = [[] for _ in range(N)]
    for i in range(N - 1):
        u, v, w = list(map(int, readline().split()))
        u, v = u - 1, v - 1
        tree[u].append((v, w))
        tree[v].append((u, w))
    color = [-1] * N
    color[0] = 0
    que = deque([0])
    while que:
        index = que.popleft()
        for next_, weight in tree[index]:
            if color[next_] == -1:
                if weight % 2 == 0:
                    color[next_] = color[index]
                else:
                    color[next_] = color[index] ^ 1
                que.append(next_)
    for c in color:
        print(c)


if __name__ == "__main__":
    main()

+import sys -from collections import Counter -from itertools import product, permutations, combinations -from operator import itemgetter -from heapq import heappop, heappush -import math -import sys -input = sys.stdin.readline -# 文字列のときはうまく行かないのでコメントアウトすること -sys.setrecursionlimit(2147483647) +readline = sys.stdin.buffer.readline +sys.setrecursionlimit(10**8) +INF = float("inf") +MOD = 10**9 + 7 -    N = int(eval(input())) -    G = [[] for i in range(N)] -    C = [-1] * N -    C[0] = 0 +    N = int(readline()) +    tree = [[] for _ in range(N)] -        u, v, w = list(map(int, input().split())) +        u, v, w = list(map(int, readline().split())) -        G[u].append((v, w)) -        G[v].append((u, w)) - -    def dfs(now): -        for ne_xt, w in G[now]: -            if C[ne_xt] == -1: -                C[ne_xt] = (C[now] + w) % 2 -                dfs(ne_xt) - -    dfs(0) -    for i in range(N): -        print((C[i])) +        tree[u].append((v, w)) +        tree[v].append((u, w)) +    color = [-1] * N +    color[0] = 0 +    que = deque([0]) +    while que: +        index = que.popleft() +        for next_, weight in tree[index]: +            if color[next_] == -1: +                if weight % 2 == 0: +                    color[next_] = color[index] +                else: +                    color[next_] = color[index] ^ 1 +                que.append(next_) +    for c in color: +        print(c)