import std.stdio;

void main() {
	int n;
	scanf("%d\n", &n);
	auto v = new int[n];
	auto u = new int[n];
	auto w = new int[n];
	auto x = new int[n];
	auto c = new int[n];
	foreach(i; 0..n) {
		int v_, u_, w_;
		scanf("%d %d %d\n", &v_, &u_, &w_);
		v[i] = v_;
		u[i] = u_;
		w[i] = w_;
	}
	bool spread = false;
	// 0 -> 未定
	// 1 -> 対象
	c[0] = 1;
	while(!spread) {
		spread = true;
		foreach(i; 0..n) {
			if (c[i] == 1) {
				spread = false;
				foreach(j; 0..n) {
					if (v[j]-1 == i) {
						x[u[j]-1] = (x[i] + w[j]) % 2;
						++c[u[j]-1];
					}
					if (u[j]-1 == i) {
						x[v[j]-1] = (x[i] + w[j]) % 2;
						++c[v[j]-1];
					}
				}
				++c[i];
			}
		}
	}
	foreach(ans; x) writeln(ans);
}
