import scala.io.{StdIn => in}
import scala.collection.{mutable => mu}
// import java.util.ArrayDeque

object Main extends App {
  val n = in.readInt

  case class edge(v:Int, d:Int)
  val tree = Array.fill(n)(mu.ListBuffer.empty[edge])

  Iterator.continually(in.readLine)
    .take(n-1)
    .map(_.split(" ").map(_.toInt))
    .foreach { case Array(v, u, d) =>
      new edge(u-1, d) +=: tree(v-1)
      new edge(v-1, d) +=: tree(u-1)
    }

  val colors = Array.ofDim[Int](n)
  val visit = Array.ofDim[Boolean](n)

  def dfs(v:Int, d:Int):Unit = {
    val stk = mu.Stack.empty[edge]
    // val stk = new ArrayDeque[edge]
    stk.push(new edge(v, d))

    while(!stk.isEmpty) {
      val v = stk.pop
      if(!visit(v.v)) {
        visit(v.v) = true
        colors(v.v) = v.d
        for(nv <- tree(v.v) if !visit(nv.v)){
          val d = (v.d + nv.d) % 2
          stk.push(new edge(nv.v, d))
        }
      }
    }
  }

  dfs(0,0)
  // println(colors.mkString("\n"))
  val out = new java.io.PrintWriter(System.out)
  colors.foreach(out.println)
  out.flush
}