import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.string;

void main() {
    auto N = readln.chomp.to!int;
    auto G = new Tuple!(int, int)[][](N);
    foreach (i; 0..N-1) {
        auto s = readln.split.map!(to!int);
        G[s[0]-1] ~= tuple(s[1]-1, s[2] & 1);
        G[s[1]-1] ~= tuple(s[0]-1, s[2] & 1);
    }

    auto ans = new int[](N);
    ans[] = 2;

    void dfs(int n, int c) {
        if (ans[n] != 2) return;
        ans[n] = c;
        foreach (to; G[n]) {
            if (ans[to[0]] != 2) continue;
            dfs(to[0], c^to[1]);
        }
    }

    dfs(0, 0);
    ans.each!writeln;
}
