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

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

alias A = Tuple!(int, "u", int, "v", int, "w");

void calc(int n, A[] a) {

    auto refs = new int[n];
    foreach (e; a) {
        refs[e.u]++;
        refs[e.v]++;
    }

    int leaf = -1;
    for (int i = 0; i < refs.length; i++) {
        if (refs[i] == 1) {
            leaf = i;
            break;
        }
    }

    A[][10^^5 + 10] adj;
    foreach (e; a) {
        adj[e.u] ~= e;
        adj[e.v] ~= e;
    }

    assert(leaf != -1);
    auto used = new int[n];
    auto colors = new int[n];
    void rec(int node, int color) {
        if (used[node]++) return;

        colors[node] = color;
        foreach (next; adj[node]) {
            if (next.w % 2 == 0) {
                rec(next.u, color);
                rec(next.v, color);
            }
            else {
                rec(next.u, color ^ 1);
                rec(next.v, color ^ 1);
            }
        }
    }
    rec(leaf, 0);


    for (int i = 0; i < colors.length; i++) {
        writeln(colors[i]);
    }
}

void main() {
    int n = readint;
    A[] a;
    for (int i = 0; i < n - 1; i++) {
        auto x = readints;
        a ~= A(x[0] - 1, x[1] - 1, x[2]);
    }
    calc(n, a);
}
