Problem:
Score : 400 points

Problem Statement

We have a tree with N vertices numbered 1 to N.
The i-th edge in the tree connects Vertex u_i and Vertex v_i, and its length is w_i.
Your objective is to paint each vertex in the tree white or black (it is fine to paint all vertices the same color) so that the following condition is satisfied:

For any two vertices painted in the same color, the distance between them is an even number.

Find a coloring of the vertices that satisfies the condition and print it. It can be proved that at least one such coloring exists under the constraints of this problem.

Constraints

All values in input are integers.

1 \leq N \leq 10^5

1 \leq u_i < v_i \leq N

1 \leq w_i \leq 10^9

Input

Input is given from Standard Input in the following format:

N
u_1 v_1 w_1
u_2 v_2 w_2
.
.
.
u_{N - 1} v_{N - 1} w_{N - 1}

Output

Print a coloring of the vertices that satisfies the condition, in N lines.
The i-th line should contain 0 if Vertex i is painted white and 1 if it is painted black.

If there are multiple colorings that satisfy the condition, any of them will be accepted.

Sample Input 1

3
1 2 2
2 3 1

Sample Output 1

0
0
1

Sample Input 2

5
2 5 2
2 3 10
1 3 8
3 4 2

Sample Output 2

1
0
1
0
1

Solution in C# (Mono 4.6.2.0) (judge verdict: Wrong Answer)

using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Runtime.CompilerServices;
using System.Security.Cryptography;
using System.Threading;
using System.Xml;
using static System.Console;
using static System.Math;
using static Ex;
using static Util;
using static IO_Z;
using static MyMath;

public struct Edge : IComparable <Edge> {

    public long To;
    public long Cost;

    public Edge(long to, long cost) {
        To = to;
        Cost = cost;
    }

    public int CompareTo(Edge e) => Cost.CompareTo(e.Cost);

}

class AC {

    /*------------------------------------------------------------------*/

    void Solve() {

        int nn;
        int[] u, v, w;
        I(out nn);
        I(out u, out v, out w, nn - 1);

        var adj = new Queue <Edge>[nn];
        nn.Rep(i => adj[i] = new Queue <Edge>());
        ZIP(u, v, w).Iter(x => { adj[x.Item1 - 1].Enqueue(new Edge(x.Item2 - 1, x.Item3)); });

        var results = new int[nn];
        nn.Rep(i => {
            var myColor = results[i];
            var sameColor = myColor;
            var diffColor = myColor == 0 ? 1 : 0;

            while (adj[i].Any()) {
                var cur = adj[i].Dequeue();
                var to = cur.To;
                var cost = cur.Cost;
                if (cost % 2 == 0) { results[to] = sameColor; }
                else { results[to] = diffColor; }
            }
        });

        results.Iter(x => x.Prt());

    }

    /*------------------------------------------------------------------*/

    void Test() {
        //--- TEST ---//
    }

    public static void Main(string[] args) => new AC().Stream();

    private void Stream() {
        SetOut(IO_Z.StreamWriter);
        /*
        var exStdIn = new http://System.IO .StreamReader("stdin.txt");
        SetIn(exStdIn);
        Test();
        */
        Solve();
        Flush();
    }

}

static class IO_Z {

    private static int Size = 1 << 12;
    private static readonly Stream Stream = OpenStandardInput();
    private static readonly byte[] Buffer = new byte[Size];
    private static int _ptr = 0, _buffLen = 0;

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    private static bool HasNextByte() {
        if (_ptr < _buffLen) return true;
        _ptr = 0;
        _buffLen = Stream.Read(Buffer, 0, Size);
        return _buffLen > 0;
    }

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    private static byte ReadByte() {
        if (HasNextByte()) return Buffer[_ptr++];
        else throw new EndOfStreamException("inputの末尾の改行がないとerror");
    }

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    private static bool IsAscii(int c) => '!' <= c && c <= '~';

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    private static char NextChar() {
        var b = ReadByte();
        while (!IsAscii(b)) b = ReadByte();
        return (char)b;
    }

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    private static string Next() {
        var sb = new StringBuilder();
        for (var b = NextChar(); IsAscii(b); b = (char)ReadByte()) sb.Append(b);
        return sb.ToString();
    }

    public static string Str => Next();
    public static char Cha => NextChar();
    public static int Int => int.Parse(Next());
    public static long Long => long.Parse(Next());
    public static double Double => double.Parse(Next());

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    private static void Scan <T>(ref T x) {
        if (x is int) __refvalue(__makeref(x), int) = int.Parse(Next());
        else if (x is long) __refvalue(__makeref(x), long) = long.Parse(Next());
        else if (x is double) __refvalue(__makeref(x), double) = double.Parse(Next());
        else if (x is char) __refvalue(__makeref(x), char) = NextChar();
        else __refvalue(__makeref(x), string) = Next();
    }

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static void I <T>(out T t) {
        t = default (T);
        Scan(ref t);
    }

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static void I <T, TU>(out T t, out TU u) {
        I(out t);
        I(out u);
    }

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static void I <T, TU, TV>(out T t, out TU u, out TV v) {
        I(out t, out u);
        I(out v);
    }

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static void I <T, TU, TV, TW>(out T t, out TU u, out TV v, out TW w) {
        I(out t, out u);
        I(out v, out w);
    }

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static void I <T, TU, TV, TW, TX>(out T t, out TU u, out TV v, out TW w, out TX x) {
        I(out t, out u, out v);
        I(out w, out x);
    }

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static void I <T, TU, TV, TW, TX, TY>(out T t, out TU u, out TV v, out TW w, out TX x, out TY y) {
        I(out t, out u, out v);
        I(out w, out x, out y);
    }

    public static void I <T>(out T[] a, int n) {
        a = new T[n];
        for (int i = 0; i < n; ++i) I(out a[i]);
    }

    public static void I <T, TU>(out T[] a, out TU[] b, int n) {
        a = new T[n];
        b = new TU[n];
        for (int i = 0; i < n; ++i) I(out a[i], out b[i]);
    }

    public static void I <T, TU, TV>(out T[] a, out TU[] b, out TV[] c, int n) {
        a = new T[n];
        b = new TU[n];
        c = new TV[n];
        for (var i = 0; i < n; ++i) I(out a[i], out b[i], out c[i]);
    }

    public static void I <T>(out T[,] a, int h, int w) {
        a = new T[h, w];
        for (int i = 0; i < h; ++i) for (int j = 0; j < w; ++j) I(out a[i, j]);
    }

    public static readonly StreamWriter StreamWriter = new StreamWriter(OpenStandardOutput()) {
#if DEBUG
        AutoFlush = true
#else
        AutoFlush = false
#endif
    };

    public static void Flush() => Out.Flush();

    public static void Prt <T>(this T x) => WriteLine(x);

    public static void Prt <T>(this T[] xs) => xs.Iter(x => WriteLine(x));

}

static class Ex {

    public static T[] Arr <T>(params T[] xs) => xs;

    public static void Iter <T>(this IEnumerable <T> xs, Action <T> f) {
        foreach (var x in xs) f(x);
    }

    public static void Rep(this int x, Action <int> f) => REP(x, f);

    public static void RepEq(this int x, Action <int> f) => REPEQ(x, f);

    public static HashSet <T> ToSet <T>(this IEnumerable <T> xs) => new HashSet <T>(xs);

}

static class Util {

    public static T IF <T>(bool b, Func <T> fTrue, Func <T> fFalse) {
        if (b) return fTrue();
        else return fFalse();
    }

    public static T LOCAL <T>(Func <T> f) => f();

    public static IEnumerable <TResult> ZIP <T1, T2, TResult>(IEnumerable <T1> xs, IEnumerable <T2> ys, Func <T1, T2, TResult> f = null) {
        using (var e1 = xs.GetEnumerator()) using (var e2 = ys.GetEnumerator()) while (e1.MoveNext() && e2.MoveNext()) yield return f(e1.Current, e2.Current);
    }

    public static IEnumerable <Tuple <T1, T2>> ZIP <T1, T2>(IEnumerable <T1> xs, IEnumerable <T2> ys)
        => ZIP(xs, ys, (x, y) => new Tuple <T1, T2>(x, y));

    public static IEnumerable <TResult> ZIP <T1, T2, T3, TResult>(IEnumerable <T1> xs, IEnumerable <T2> ys, IEnumerable <T3> zs, Func <T1, T2, T3, TResult> f) {
        using (var e1 = xs.GetEnumerator()) using (var e2 = ys.GetEnumerator()) using (var e3 = zs.GetEnumerator()) while (e1.MoveNext() && e2.MoveNext() && e3.MoveNext()) yield return f(e1.Current, e2.Current, e3.Current);
    }

    public static IEnumerable <Tuple <T1, T2, T3>> ZIP <T1, T2, T3>(IEnumerable <T1> xs, IEnumerable <T2> ys, IEnumerable <T3> zs) => ZIP(xs, ys, zs, (x, y, z) => new Tuple <T1, T2, T3>(x, y, z));

    public static IEnumerable <T> UNFOLD <T>(T x, Func <T, T> f, Func <T, bool> until = null) {
        if (until == null) until = (_) => true;
        yield return x;
        var newX = f(x);
        while (until(newX)) {
            yield return newX;
            newX = f(newX);
        }
    }

    public static void FOR(int a, int b, int n, Action <int> f) {
        for (var i = a; i < b; i += n) f(i);
    }

    public static void FOREQ(int a, int b, int n, Action <int> f) => FOR(a, b + 1, n, f);

    public static void FOR(int a, int b, Action <int> f) => FOR(a, b, 1, f);

    public static void FOREQ(int a, int b, Action <int> f) => FOREQ(a, b, 1, f);

    public static void REP(int a, Action <int> f) => FOR(0, a, f);

    public static void REPEQ(int a, Action <int> f) => FOR(0, a + 1, f);

    public static T MIN <T>(params T[] xs) => xs.Min();

    public static T MAX <T>(params T[] xs) => xs.Max();

    public static IEnumerable <int> RANGE(int s, int e) => Enumerable.Range(s, e - s + 1);

}

static class MyMath {

    public static int GCD(int a, int b) => (a < b) ? GCD(b, a) : b == 0 ? a : GCD(b, a % b);

    public static int GCD(params int[] xs) => xs.Aggregate(GCD);

    public static long GCD(long a, long b) => (a < b) ? GCD(b, a) : b == 0L ? a : GCD(b, a % b);

    public static long GCD(params long[] xs) => xs.Aggregate(GCD);

    public static int LCM(int a, int b) => a * (b / GCD(a, b));

    public static int LCM(params int[] xs) => xs.Aggregate(LCM);

    public static long LCM(long a, long b) => a * (b / GCD(a, b));

    public static long LCM(params long[] xs) => xs.Aggregate(LCM);

}