import queue

n=int(eval(input()))

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

INF=10**18

d=[INF]*n

for _ in range(n-1):

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

  e[v-1]+=[(u-1,w)]

  e[u-1]+=[(v-1,w)]

q=queue.Queue()

q.put(0)

d[0]=0

while not q.empty():

  now=q.get()

  for to,dis in e[now]:

    if d[to]==INF:

      d[to]=d[now]+dis

      q.put(to)

for i in d:

  print((i%2))
from collections import deque

n=int(input())

e=[[]for _ in range(n+1)]

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

for _ in range(n-1):

  a,b,w=map(int,input().split())

  e[a]+=[(b,w)]

  e[b]+=[(a,w)]

q=deque([1])

c[1]=0

while q:

  now=q.popleft()

  for to,w in e[now]:

    if c[to]==-1:

      c[to]=(c[now]+w)%2

      q.append(to)

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

import queue

n = int(eval(input()))
e = [[] for _ in range(n)]
INF = 10**18
d = [INF] * n
for _ in range(n - 1):
    v, u, w = list(map(int, input().split()))
    e[v - 1] += [(u - 1, w)]
    e[u - 1] += [(v - 1, w)]
q = queue.Queue()
q.put(0)
d[0] = 0
while not q.empty():
    now = q.get()
    for to, dis in e[now]:
        if d[to] == INF:
            d[to] = d[now] + dis
            q.put(to)
for i in d:
    print((i % 2))

from collections import deque

n = int(input())
e = [[] for _ in range(n + 1)]
c = [-1] * (n + 1)
for _ in range(n - 1):
    a, b, w = map(int, input().split())
    e[a] += [(b, w)]
    e[b] += [(a, w)]
q = deque([1])
c[1] = 0
while q:
    now = q.popleft()
    for to, w in e[now]:
        if c[to] == -1:
            c[to] = (c[now] + w) % 2
            q.append(to)
print(*c[1:], sep="\n")

-import queue +from collections import deque -n = int(eval(input())) -e = [[] for _ in range(n)] -INF = 10**18 -d = [INF] * n +n = int(input()) +e = [[] for _ in range(n + 1)] +c = [-1] * (n + 1) -    v, u, w = list(map(int, input().split())) -    e[v - 1] += [(u - 1, w)] -    e[u - 1] += [(v - 1, w)] -q = queue.Queue() -q.put(0) -d[0] = 0 -while not q.empty(): -    now = q.get() -    for to, dis in e[now]: -        if d[to] == INF: -            d[to] = d[now] + dis -            q.put(to) -for i in d: -    print((i % 2)) +    a, b, w = map(int, input().split()) +    e[a] += [(b, w)] +    e[b] += [(a, w)] +q = deque([1]) +c[1] = 0 +while q: +    now = q.popleft() +    for to, w in e[now]: +        if c[to] == -1: +            c[to] = (c[now] + w) % 2 +            q.append(to) +print(*c[1:], sep="\n")