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 sys.setrecursionlimit(10**5) sys.setrecursionlimit sys setrecursionlimit 10**5 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]) f 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]) tmp links[x] 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]) c[tmp[0]]<0 c[tmp[0]] c tmp[0] tmp 0 0 if tmp[1]%2==0:
        c[tmp[0]]=c[x]+0
      else:
        c[tmp[0]]=1-c[x]
       tmp[1]%2==0 tmp[1]%2 tmp[1] tmp 1 2 0 c[tmp[0]]=c[x]+0 c[tmp[0]] c tmp[0] tmp 0 c[x]+0 c[x] c x 0 c[tmp[0]]=1-c[x] c[tmp[0]] c tmp[0] tmp 0 1-c[x] 1 c[x] c x f(tmp[0]) f tmp[0] tmp 0 x x 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) [] links=[[] for _ in range(N+1)] 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])
   _ range(N-1) range N-1 N 1 u, v, w=map(int, input().split()) u map(int, input().split()) map int input().split() ().split () input split v w links[u].append([v, w]) [u].append [u] links u append [v, w] v w links[v].append([u, w]) [v].append [v] links v append [u, w] u w c=[-1]*(N+1) c [-1]*(N+1) [-1] -1 N+1 N 1 c[1]=0 c[1] c 1 0 f(1) f 1 print(*c[1:], sep='\n') print *c[1:] c[1:] c 1: 1 sep='\n' sep '\n' 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]) 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]) f links=[[] for _ in range(N+1)] [[] for _ in range(N+1)] links w=map(int, input().split()) map(int, input().split()) w v, w=map(int, input().split()) map(int, input().split()) v N=int(input()) int(input()) N u, v, w=map(int, input().split()) map(int, input().split()) u c=[-1]*(N+1) [-1]*(N+1) c
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')