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') from collections import deque n=int(input()) n int(input()) int input() input []for _ in range(n+1) for _ in range(n+1) _ range(n+1) range n+1 n 1 for _ in range(n+1) [] e=[[]for _ in range(n+1)] e [[]for _ in range(n+1)] c=[-1]*(n+1) c [-1]*(n+1) [-1] -1 n+1 n 1 for _ in range(n-1):
  a,b,w=map(int,input().split())
  e[a]+=[(b,w)]
  e[b]+=[(a,w)] _ range(n-1) range n-1 n 1 a,b,w=map(int,input().split()) a map(int,input().split()) map int input().split() ().split () input split b w e[a]+=[(b,w)] e[a] e a [(b,w)] (b,w) b w e[b]+=[(a,w)] e[b] e b [(a,w)] (a,w) a w q=deque([1]) q deque([1]) deque [1] 1 c[1]=0 c[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) q now=q.popleft() now q.popleft() q.popleft q popleft for to,w in e[now]:
    if c[to]==-1:
      c[to]=(c[now]+w)%2
      q.append(to) to w e[now] e now if c[to]==-1:
      c[to]=(c[now]+w)%2
      q.append(to) c[to]==-1 c[to] c to -1 c[to]=(c[now]+w)%2 c[to] c to (c[now]+w)%2 c[now]+w c[now] c now w 2 q.append(to) q.append q append to print(*c[1:],sep='\n') print *c[1:] c[1:] c 1: 1 sep='\n' sep '\n' a,b,w=map(int,input().split()) map(int,input().split()) a b,w=map(int,input().split()) map(int,input().split()) b n=int(input()) int(input()) n e=[[]for _ in range(n+1)] [[]for _ in range(n+1)] e c=[-1]*(n+1) [-1]*(n+1) c q=deque([1]) deque([1]) q w=map(int,input().split()) map(int,input().split()) w now=q.popleft() q.popleft() now
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')