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;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Math;
using static System.Console;


class Program
{
    public class Tree
    {
        public class Node
        {
            public int? Parent = null;
            public List<int[]> Children = new List<int[]>();
            public long D = 0;
        }

        public Tree(int nodeNumber)
        {
            Nodes = new Node[nodeNumber];
            for (int i = 0; i < Nodes.Length; i++)
            {
                Nodes[i] = new Node();
                Connenters = new List<int[]>();
            }
        }

        /// <summary>
        /// 頂点の配列。それぞれの頂点には、一つの親と、複数の子がある
        /// </summary>
        public Node[] Nodes { get; }

        public List<int[]> Connenters { get; }

        public void Connent(int to, int from, long id = -1)
        {
            int p = -1;
            int c = -1;
            if (Connenters.Count == 0)
            {
                p = to;
                c = from;
            }
            else
            {
                if (Nodes[to].Children.Count == 0&& Nodes[to].Parent==null)
                {
                    c = to;
                    p = from;
                }
                else
                {
                    p = to;
                    c = from;
                }
            }
            Connenters.Add(new int[3] { to, from, 0 });
            Nodes[c].Parent = p;
            Nodes[p].Children.Add(new int[2] { from, (int)id });
            Nodes[c].D = Nodes[p].D + id;
        }


        static void Main()
        {
            int N = ReadInt();
            Tree tree = new Tree(N);
            for (int i = 0; i < N - 1; i++)
            {
                int[] uvw = ReadIntN();
                int u = uvw[0] - 1;
                int v = uvw[1] - 1;
                int w = uvw[2];

                tree.Connent(u, v, w);
            }

            for (int i = 0; i < tree.Nodes.Length; i++)
            {
                //if (tree.Nodes[i].D % 2 == 0) WriteLine(0);
                //else WriteLine(1);
                WriteLine(tree.Nodes[i].D);
            }
            ReadLine();
        }

        #region Reader
        static string ReadStr()
        {
            return Console.ReadLine();
        }
        static string[] ReadStrN()
        {
            return Console.ReadLine().Split(' ');
        }
        static int ReadInt()
        {
            return Convert.ToInt32(Console.ReadLine());
        }
        static int[] ReadIntN()
        {
            return Console.ReadLine().Split(' ').Select(s => Convert.ToInt32(s)).ToArray();
        }
        static long ReadLong()
        {
            return Convert.ToInt64(Console.ReadLine());
        }
        static long[] ReadLongN()
        {
            return Console.ReadLine().Split(' ').Select(s => Convert.ToInt64(s)).ToArray();
        }
        static long[,] ReadLongMatrix(int r, int c)
        {
            var mat = new long[r, c];
            for (int i = 0; i < r; ++i)
            {
                var x = ReadLongN();
                for (int j = 0; j < c; ++j)
                {
                    mat[i, j] = x[j];
                }
            }
            return mat;
        }
        static Tuple<string, string>[] ReadTupleStr(int n)
        {
            List<Tuple<string, string>> list = new List<Tuple<string, string>>();
            for (int i = 0; i < n; ++i)
            {
                var ab = ReadStrN();
                list.Add(new Tuple<string, string>(ab[0], ab[1]));
            }
            return list.ToArray();
        }
        static Tuple<long, long>[] ReadTupleLong(int n)
        {
            List<Tuple<long, long>> list = new List<Tuple<long, long>>();
            for (int i = 0; i < n; ++i)
            {
                var ab = ReadLongN();
                list.Add(new Tuple<long, long>(ab[0], ab[1]));
            }
            return list.ToArray();
        }
        static Tuple<int, int>[] ReadTupleInt(int n)
        {
            List<Tuple<int, int>> list = new List<Tuple<int, int>>();
            for (int i = 0; i < n; ++i)
            {
                var ab = ReadIntN();
                list.Add(new Tuple<int, int>(ab[0], ab[1]));
            }
            return list.ToArray();
        }
        static Tuple<double, double>[] ReadTupleDouble(int n)
        {
            List<Tuple<double, double>> list = new List<Tuple<double, double>>();
            for (int i = 0; i < n; ++i)
            {
                var ab = ReadLongN();
                list.Add(new Tuple<double, double>(ab[0], ab[1]));
            }
            return list.ToArray();
        }
        static Dictionary<int, HashSet<int>> ReadAdjacencyList(int N, int M)
        {
            Dictionary<int, HashSet<int>> dict = new Dictionary<int, HashSet<int>>();
            for (int i = 0; i <= N; ++i)
            {
                dict.Add(i, new HashSet<int>());
            }
            for (int i = 0; i < M; ++i)
            {
                var ab = ReadIntN();
                dict[ab[0]].Add(ab[1]);
                dict[ab[1]].Add(ab[0]);
            }
            return dict;
        }
        #endregion
    }
}