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

ulong MAX = 1_000_100, MOD = 1_000_000_007, INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias lread(T = long) = () => readln.chomp.to!(T);
alias aryread(T = long) = () => readln.split.to!(T[]);
alias Node = Tuple!(long, "p", long, "dist");
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);

void main()
{
    auto n = lread();
    auto TREE = new Node[][](n, 0);
    auto color = new long[](n);
    foreach (_; iota(n - 1))
    {
        long u, v, w;
        scan(u, v, w);
        TREE[u - 1] ~= Node(v - 1, w);
        TREE[v - 1] ~= Node(u - 1, w);
    }
    // TREE.each!(x => x.writeln());
    color[0] = 1;
    dfs(TREE, color, 0, 0);
    foreach (e; color)
        writeln(e - 1);
}

void dfs(T)(T tree, long[] color, long current, long dist)
{
    foreach (node; tree[current])
    {
        if (!color[node.p])
        {
            if ((dist + node.dist) % 2)
                color[node.p] = 2;
            else
                color[node.p] = 1;
            dfs(tree, color, node.p, dist + node.dist);
        }
    }
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}
