n = gets.strip.to_i
colors = Array.new(n)

(1...n).each do |i|
  u, v, w = gets.strip.split(' ').map(&:to_i)
  u -= 1
  v -= 1
  if w % 2 == 0 then
    if colors[u] && colors[v] then
      colors.map! { |c| c = colors[u] if c == colors[v] } if colors[u] != colors[v]
    elsif colors[u] && !colors[v] then
      colors[v] = colors[u]
    elsif !colors[u] && colors[v] then
      colors[u] = colors[v]
    else
      colors[u] = i
      colors[v] = i
    end
  else
    if colors[u] && !colors[v] then
      colors[v] = i
    elsif !colors[u] && colors[v] then
      colors[u] = i
    else
      colors[u] = i
      colors[v] = n + i
    end
  end
end

uniq = colors.uniq
puts colors.map { |c| uniq.index(c) }
