import std.stdio, std.conv, std.array, std.string, std.algorithm, std.range, std.typecons;


void main() {
    long n;
    readf("%d\n", &n);

    alias T = Tuple!(long, long);
    T[][] nexts = new T[][](n);
    foreach (_; 0..n-1) {
        auto uvw = readln.split.map!(to!long).array;
        long u = uvw[0]-1, v = uvw[1]-1, w = uvw[2];
        nexts[u] ~= T(v, w % 2);
        nexts[v] ~= T(u, w % 2);
    }

    auto dists = new int[](n);
    dists[] = -1;

    void dfs(long cur, long prev, long dist) {
        dists[cur] = dist % 2;
        foreach (next; nexts[cur]) {
            if (next[0] == prev) {
                continue;
            }
            dfs(next[0], cur, (dist + next[1]) % 2);
        }
    }
    dfs(0, -1, 0);

    foreach (ans; dists) {
        writeln(ans);
    }
}
