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: Runtime Error)

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using static System.Math;

namespace Sample
{
    public class Program
    {
        public static void Main(string[] args)
        {
            using (var sc = new SetConsole()) { Solve(); }
        }

        public static void Solve()
        {
            var n = GetString().ToInt();
            var u = new List<int[]>();
            for (int i = 0; i < n - 1; i++)
            {
                u.Add(GetArray<int>());
            }
            // -1 1= 白 2 = 黒
            var colors = new int[n + 1];
            for (int i = 0; i < colors.Length; i++)
            {
                colors[i] = -1;
            }
            var map = new int[n + 1, n + 1];
            foreach (var item in u)
            {
                map[item[0], item[1]] = item[2];
                map[item[1], item[0]] = item[2];
            }

            for (int i = 1; i < n + 1; i++)
            {
                for (int j = 1; j < i; j++)
                {
                    if (map[i, j] == 0) { continue; }
                    if (map[i, j] % 2 == 0)
                    {
                        if (colors[i] >= 0)
                        {
                            colors[j] = colors[i];
                        }
                        else if (colors[j] >= 0)
                        {
                            colors[i] = colors[j];
                        }
                        else
                        {
                            colors[i] = colors[j] = 0;
                        }
                    }
                    else
                    {
                        if (colors[i] == 0)
                        {
                            colors[j] = 1;
                        }
                        else if (colors[i] == 1)
                        {
                            colors[j] = 0;
                        }
                        if (colors[j] == 0)
                        {
                            colors[i] = 1;
                        }
                        else if (colors[j] == 1)
                        {
                            colors[i] = 0;
                        }
                        else if (colors[i] == -1 && colors[j] == -1)
                        {
                            colors[i] = 0;
                            colors[j] = 1;
                        }
                    }
                }
            }
            foreach (var color in colors.Skip(1))
            {
                CWrite(color);
            }
        }


        static void CWrite<T>(T str) => Console.WriteLine(str);
        static string GetString() => Console.ReadLine();
        static T[] GetArray<T>()
        {
            var t = typeof(T);
            var str = Console.ReadLine();

            if (t == typeof(string))
            {
                return (T[])(object)str.Split();
            }
            if (t == typeof(int))
            {
                return (T[])(object)str.ToNumArray<T>();
            }
            if (t == typeof(long))
            {
                return (T[])(object)str.ToNumArray<T>();
            }
            if (t == typeof(double))
            {
                return (T[])(object)str.ToNumArray<T>();
            }
            throw new NotSupportedException($"{t} is not supported.");
        }
    }



    class SetConsole : IDisposable
    {
        readonly StreamWriter sw = new StreamWriter(Console.OpenStandardOutput());
        public SetConsole()
        {
            sw.AutoFlush = false;
            Console.SetOut(sw);
        }
        public void Dispose()
        {
            Console.Out.Flush();
            sw.AutoFlush = true;
            Console.SetOut(sw);
        }
    }

    static class ExtentionsLibrary
    {
        public static T[] CopyArray<T>(this T[] array)
        {
            var newArray = new T[array.Length];
            Array.Copy(array, newArray, array.Length);
            return newArray;
        }
        public static T[,] CopyArray<T>(this T[,] array)
        {
            var firstDimentionLength = array.GetLength(0);
            var secondDimentionLength = array.GetLength(1);
            var newDArray = new T[firstDimentionLength, secondDimentionLength];
            Array.Copy(array, newDArray, firstDimentionLength * secondDimentionLength);
            return newDArray;
        }
        public static T[] ToNumArray<T>(this string str)
        {
            var t = typeof(T);
            if (t == typeof(int))
            {
                return (T[])(object)str.Split().Select(int.Parse).ToArray();
            }
            if (t == typeof(long))
            {
                return (T[])(object)str.Split().Select(long.Parse).ToArray();
            }
            if (t == typeof(double))
            {
                return (T[])(object)str.Split().Select(double.Parse).ToArray();
            }
            throw new NotSupportedException();
        }
        public static int ToInt(this string str) => int.Parse(str);
        public static int ToInt(this char chr) => int.Parse(chr.ToString());
        public static long ToLong(this string str) => long.Parse(str);
        public static DateTime ToDateTime(this string str) => DateTime.Parse(str);
    }
}