import Foundation
let N = Int(readLine()!)!

// -1: not determined, 0: black, 1: white
var graph: [[(Int, Int)]] = .init(repeating: [], count: N)
var colors: [Int] = .init(repeating: 0, count: N)
var indegrees: [Int] = .init(repeating: 0, count: N)

for _ in 0..<N-1 {
  let input = readLine()!.split(separator: " ").map { Int($0)! }
  graph[input[0] - 1].append((input[1] - 1, input[2] & 1))
  indegrees[input[1] - 1] += 1
}


var roots = Set<Int>()
for i in 0..<indegrees.count {
  if indegrees[i] == 0 {
    roots.insert(i)
  }
}

func dfs(_ root: Int, _ current: Int) {
  colors[root] = current
  for nei in graph[root] {
    let index = nei.0
    let distance = nei.1
    dfs(index, current ^ distance)
  }
}

for root in roots {
  dfs(root, 0)
}
colors.forEach { print($0) }
