import sys

sys.setrecursionlimit(10**5+1)



N=int(eval(input()))

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

nodelink=[[] for i in range(N+1)]

for i in range(N-1):

  nodelink[uvw[i][0]].append([uvw[i][1], uvw[i][2]])

  nodelink[uvw[i][1]].append([uvw[i][0], uvw[i][2]])

  

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



def f(nuru, iro):

  color[nuru]=iro

  tonari=nodelink[nuru]

  for nuruyo in tonari:

    if color[nuruyo[0]]<0:

      if (nuruyo[1]%2)==0:

        f(nuruyo[0], iro)

      else:

        f(nuruyo[0], 1-iro)

      

f(1, 0)



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

  print((color[i]))
import sys

sys.setrecursionlimit(10**5)



def f(x):

  for tmp in links[x]:

    if c[tmp[0]]<0:

      if tmp[1]%2==0:

        c[tmp[0]]=c[x]+0

      else:

        c[tmp[0]]=1-c[x]

      f(tmp[0])



N=int(input())

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

for _ in range(N-1):

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

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

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

  

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

c[1]=0

f(1)



print(*c[1:], sep='\n')

import sys

sys.setrecursionlimit(10**5 + 1)
N = int(eval(input()))
uvw = [list(map(int, input().split())) for i in range(N - 1)]
nodelink = [[] for i in range(N + 1)]
for i in range(N - 1):
    nodelink[uvw[i][0]].append([uvw[i][1], uvw[i][2]])
    nodelink[uvw[i][1]].append([uvw[i][0], uvw[i][2]])
color = [-1] * (N + 1)


def f(nuru, iro):
    color[nuru] = iro
    tonari = nodelink[nuru]
    for nuruyo in tonari:
        if color[nuruyo[0]] < 0:
            if (nuruyo[1] % 2) == 0:
                f(nuruyo[0], iro)
            else:
                f(nuruyo[0], 1 - iro)


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

import sys

sys.setrecursionlimit(10**5)


def f(x):
    for tmp in links[x]:
        if c[tmp[0]] < 0:
            if tmp[1] % 2 == 0:
                c[tmp[0]] = c[x] + 0
            else:
                c[tmp[0]] = 1 - c[x]
            f(tmp[0])


N = int(input())
links = [[] for _ in range(N + 1)]
for _ in range(N - 1):
    u, v, w = map(int, input().split())
    links[u].append([v, w])
    links[v].append([u, w])
c = [-1] * (N + 1)
c[1] = 0
f(1)
print(*c[1:], sep="\n")

-sys.setrecursionlimit(10**5 + 1) -N = int(eval(input())) -uvw = [list(map(int, input().split())) for i in range(N - 1)] -nodelink = [[] for i in range(N + 1)] -for i in range(N - 1): -    nodelink[uvw[i][0]].append([uvw[i][1], uvw[i][2]]) -    nodelink[uvw[i][1]].append([uvw[i][0], uvw[i][2]]) -color = [-1] * (N + 1) +sys.setrecursionlimit(10**5) -def f(nuru, iro): -    color[nuru] = iro -    tonari = nodelink[nuru] -    for nuruyo in tonari: -        if color[nuruyo[0]] < 0: -            if (nuruyo[1] % 2) == 0: -                f(nuruyo[0], iro) +def f(x): +    for tmp in links[x]: +        if c[tmp[0]] < 0: +            if tmp[1] % 2 == 0: +                c[tmp[0]] = c[x] + 0 -                f(nuruyo[0], 1 - iro) +                c[tmp[0]] = 1 - c[x] +            f(tmp[0]) -f(1, 0) -for i in range(1, N + 1): -    print((color[i])) +N = int(input()) +links = [[] for _ in range(N + 1)] +for _ in range(N - 1): +    u, v, w = map(int, input().split()) +    links[u].append([v, w]) +    links[v].append([u, w]) +c = [-1] * (N + 1) +c[1] = 0 +f(1) +print(*c[1:], sep="\n")