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: Accepted)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace AtCoder
{
	public class Program
	{
		//static int[] parent;
		static void Main(string[] args)
		{
			int[] input = Console.ReadLine().Split().Select(p => int.Parse(p)).ToArray();
			int N = input[0];
			//int K = input[1];

			// 頂点から伸びる頂点とその距離のリスト
			List<List<List<int>>> tree = new List<List<List<int>>>();
			// 初期化
			for(int i=0; i<N; i++)
			{
				List<List<int>> list = new List<List<int>>();
				tree.Add(list);
			}

//Console.WriteLine("debug2 " + tree.Count);
			for(int i=0; i<N-1; i++)
			{
			//	Console.WriteLine("debug3 " + i);
				input = Console.ReadLine().Split().Select(p => int.Parse(p)).ToArray();
				// input[0]->input[1] の距離はinput[2]
				List<int> d = new List<int>();
				d.Add(input[1]);
				d.Add(input[2]);
				tree[input[0]-1].Add(d);

				// 逆向きも
				List<int> d2 = new List<int>();
				d2.Add(input[0]);
				d2.Add(input[2]);
				tree[input[1]-1].Add(d2);
			}
//Console.WriteLine("debug1");
			int[] color = new int[N];
			//HashSet<int> hs = new HashSet<int>();
			// color[0]=0
			//hs.Add(0);
			for(int i=1; i<N; i++)
			{
				color[i] = -1;
				//hs.Add(i);
			}

			// 塗り分けする
			coloring(0, tree, color);
			/*while(hs.Count > 0)
			{
				HashSet<int> dl = new HashSet<int>();
				foreach(var i in hs)
				{
					int c = color[i]; // iは何色
					if(c<0)// || comp[i] == 1)
					{
						continue; // 色未定orすでに行き先塗ってたら飛ばす
					}
					// 行き先を全て塗るとhsから外す
					dl.UnionWith(coloring(i, tree, color));
				}

				foreach(var a in dl)
				{
					hs.Remove(a);
				}
			}
			*/

			// 色分け終わり
			for(int i=0; i<N; i++)
				Console.WriteLine(color[i] + "") ;
		}

		static void coloring(int i, List<List<List<int>>> tree, int[] color)
		{
			// 行き先を深さ優先探索する
			//HashSet<int> ret = new HashSet<int>();
			//ret.Add(i);
			List<List<int>> leef = tree[i];
			for(int j=0; j<leef.Count; j++)
			{
				int node = leef[j][0]-1; // 行き先番号
				if(color[node]>=0)
					continue; // すでに塗られていたらOK

				if(leef[j][1]%2 == 0)
					color[node] = color[i];
				else
					color[node] = (color[i]+1)%2;

			 coloring(node, tree, color);
				//ret.UnionWith(coloring(node, tree, color));
			}

			//return ret;
		}
	}
}