from collections import deque



n=int(eval(input()))



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

for i in range(n-1):

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

  u-=1

  v-=1

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

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



dist=[-1]*n

dist[0]=0



ans=[-1]*n

ans[0]=0



dq=deque()

dq.append(0)



while dq:

  x=dq.popleft()

  for vv,ww in tree[x]:

    if dist[vv]==-1:

      dq.append(vv)

      dist[vv]=dist[x]+ww

      if dist[vv]%2==0:

        ans[vv]=0

      else:

        ans[vv]=1



for i in ans:

  print(i)
from collections import deque

from sys import stdin

nii=lambda:list(map(int,stdin.readline().split()))



n=int(eval(input()))



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

for i in range(n-1):

  u,v,w=nii()

  u-=1

  v-=1

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

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



ans=[-1 for i in range(n)]

ans[0]=0



que=deque()

que.append(0)



while que:

  x=que.popleft()

  for i in tree[x]:

    nx=i[0]

    nw=i[1]

    if ans[nx]==-1:

      que.append(nx)

      if nw%2==0:

        ans[nx]=ans[x]

      else:

        ans[nx]=(ans[x]+1)%2



for i in ans:

  print(i)
from collections import deque

n = int(eval(input()))
tree = [[] for i in range(n)]
for i in range(n - 1):
    u, v, w = list(map(int, input().split()))
    u -= 1
    v -= 1
    tree[u].append([v, w])
    tree[v].append([u, w])
dist = [-1] * n
dist[0] = 0
ans = [-1] * n
ans[0] = 0
dq = deque()
dq.append(0)
while dq:
    x = dq.popleft()
    for vv, ww in tree[x]:
        if dist[vv] == -1:
            dq.append(vv)
            dist[vv] = dist[x] + ww
            if dist[vv] % 2 == 0:
                ans[vv] = 0
            else:
                ans[vv] = 1
for i in ans:
    print(i)

from collections import deque
from sys import stdin

nii = lambda: list(map(int, stdin.readline().split()))
n = int(eval(input()))
tree = [[] for i in range(n)]
for i in range(n - 1):
    u, v, w = nii()
    u -= 1
    v -= 1
    tree[u].append([v, w])
    tree[v].append([u, w])
ans = [-1 for i in range(n)]
ans[0] = 0
que = deque()
que.append(0)
while que:
    x = que.popleft()
    for i in tree[x]:
        nx = i[0]
        nw = i[1]
        if ans[nx] == -1:
            que.append(nx)
            if nw % 2 == 0:
                ans[nx] = ans[x]
            else:
                ans[nx] = (ans[x] + 1) % 2
for i in ans:
    print(i)

+from sys import stdin +nii = lambda: list(map(int, stdin.readline().split())) -    u, v, w = list(map(int, input().split())) +    u, v, w = nii() -dist = [-1] * n -dist[0] = 0 -ans = [-1] * n +ans = [-1 for i in range(n)] -dq = deque() -dq.append(0) -while dq: -    x = dq.popleft() -    for vv, ww in tree[x]: -        if dist[vv] == -1: -            dq.append(vv) -            dist[vv] = dist[x] + ww -            if dist[vv] % 2 == 0: -                ans[vv] = 0 +que = deque() +que.append(0) +while que: +    x = que.popleft() +    for i in tree[x]: +        nx = i[0] +        nw = i[1] +        if ans[nx] == -1: +            que.append(nx) +            if nw % 2 == 0: +                ans[nx] = ans[x] -                ans[vv] = 1 +                ans[nx] = (ans[x] + 1) % 2