process.stdin.resume();
process.stdin.setEncoding('utf8'); 
var lines = [];
var reader = require('readline').createInterface({
	input: process.stdin,
	output: process.stdout
});
 
reader.on('line', (line) => {
	lines.push(line);
});

reader.on('close', () => {
	"use strict"
	const N = +lines[0];
	const uvw = Array.from(Array(N-1), (e,i) => lines[i+1].split(" ").map(Number));
	const u = uvw.map(e => e[0]-1);
	const v = uvw.map(e => e[1]-1);
	const w = uvw.map(e => e[2]);
	
	const tree = Array.from(Array(N), () => new Set());
	const color = Array.from(Array(N), () => null);
	
	for(let i=0; i<N-1; i++){
		tree[u[i]].add([v[i], w[i]]);
		tree[v[i]].add([u[i], w[i]]);
	}
	
	const que = [];
	const setColor = (x, col) => {
		color[x] = col;
		for(let e of tree[x]){
			const y = e[0];
			const d = e[1];
			if(color[y]===null){que.push([y, col^(d%2)])}
		}
	}
	
	setColor(0,0);
	while(que.length){
		const y = que.shift();
		setColor(y[0],y[1]);
	}
	
	let ans = color.join("\n");
	
	console.log(ans);
});