private data class Edge(val to: Int, val w: Int)

fun main(args: Array<String>) {
    val n = readLine()!!.toInt()

    val color = IntArray(n) { -1 }

    var adjList = mutableListOf<MutableList<Edge>>()
    for (i in 0 until n) {
        adjList.add(mutableListOf<Edge>())
    }

    for (i in 0 until n - 1) {
        val (s, t, w) = readLine()!!.split(" ").map { it.toInt() }
        adjList[s-1].add(Edge(t-1, w))
        adjList[t-1].add(Edge(s-1, w))
    }

    color[0] = 0

    fun paintWithDfs(from: Int, now: Int, distance: Int) {

        if (distance % 2 == 0) {
            color[now] = if (color[from] == 0) 0 else 1
        } else {
            color[now] = if (color[from] == 0) 1 else 0
        }

        for (e in adjList[now]) {
            if (e.to == from) {
                continue
            }
            paintWithDfs(from = now, now = e.to, distance = e.w)
        }
    }

    paintWithDfs(0, 0, 0)

    for (c in color){
        println(c)
    }
}