import java.util.ArrayDeque
fun coloring(matrix: MutableMap<Int, MutableMap<Int,Long>>,num_nodes:Int) : Array<Boolean?> {

    val color_allocation: Array<Boolean?> = arrayOfNulls(num_nodes)

        val index_queue: ArrayDeque<Int> = ArrayDeque()
        val root_index = color_allocation.indices.first {color_allocation[it] == null }
        
        color_allocation[root_index] = true
        index_queue.add(root_index)

        while(! index_queue.isEmpty()) {
            val index = index_queue.poll()
            matrix[index]?.forEach { 
                    if(color_allocation[it.key] == null) {
                        index_queue.add(it.key)
                        it.value.run { 
                            color_allocation[it.key] = color_allocation[index]?.let { c->
                                c xor (this % 2 != 0L) 
                            }
                        }                    
                    }
            }
        }
    // color_allocation.forEach{print("${it} ")}
    // println()
    return color_allocation
}
fun main(args:Array<String>) {
    val N = readLine()!!.toInt()
    val graph:MutableMap<Int, MutableMap<Int,Long>> = mutableMapOf()
    1.until(N).forEach {
        val (u,v,w) = readLine()!!.split(" ").map(String::toLong)
        val (i,j) = Pair((u-1).toInt(), (v-1).toInt())
        // graph[i][j] = w 
        // graph[j][i] = w
        if(!graph.contains(i)) {
            graph.set(i, mutableMapOf())
        }
        if(!graph.contains(j)) {
            graph.set(j, mutableMapOf())
        }
        graph[i]!!.set(j, w)
        graph[j]!!.set(i, w)
    }
    // graph.values.forEach {row ->
    //     row.values.forEach {
    //     print("${it} ")
    //     }
    //     println()
    // }
    // println()
    
    val color_allocation = coloring(graph,N)

    color_allocation.forEach {
        ((it?.let{c -> if(c) {"1"} else {"0"}}) ?: "-1").run(::println)
    }
}
