N = gets.to_i
edges = N.times.map{ [] }
$<.each{|s|
  from, to, dst = s.split.map &:to_i
  sign = dst.even? ? 1 : -1
  edges[from-1] << (to-1) * sign
  edges[to-1] << (from-1) * sign
}
visited = [false] * N
# p edges

f = ->from{
  return if visited[from.abs]
  visited[from.abs] = from >= 0 ? 0 : 1
  edges[from].each{|to|
    f[to]
  }
}
f[0]

puts visited
