#!/usr/bin/ruby

require 'pp'

N = gets.chomp.to_i

queue = []
table = [nil]*(N)
1.upto(N-1){|e|

u,v,w = gets.chomp.split(" ").map(&:to_i)
   if table[u] == nil
        table[u] = {color: -1, neibours: [] }
   end

   if table[v] == nil
        table[v] = {color: -1, neibours: [] }
   end

   table[u][:neibours] << [v,w]
   table[v][:neibours] << [u,w]

   if e == 1
      queue << u
      table[u][:color] = 0
   end
}



while !queue.empty? do
    i = queue.shift
    c = table[i][:color]
    table[i][:neibours].each{|node|
       if table[ node[0] ][:color] == -1
          table[ node[0] ][:color] = (node[1]%2 == 0 ? c : c^1)
          queue << node[0]
       end
    }
end


1.upto(N){|n|
  puts table[n][:color]
}