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.Text;

namespace AtCoder
{
	public class Program
	{
		static int[] Nodes;

		static void Main(string[] args)
		{
			int N = int.Parse(Console.ReadLine());
			Nodes = new int[N];

			int c1 = 1, c2 = 2;
			for (int i = 0; i < N - 1; i++) {
				int[] vs = Console.ReadLine().Split().Select(p => int.Parse(p)).ToArray();
				int node1 = vs[0] - 1;
				int node2 = vs[1] - 1;
				bool distance = vs[2] % 2 == 0;
				if (Nodes[node1] != 0 && Nodes[node2] != 0) {
					// Node1 Node2 設定済み
					if (distance) {
						// 偶数なら同じ色
						if (Nodes[node1] % 2 != Nodes[node2] % 2) {
							SwapColor(Nodes[node2]);
						}
					} else {
						// 奇数なら違う色
						if (Nodes[node1] % 2 == Nodes[node2] % 2) {
							SwapColor(Nodes[node2]);
						}
					}
				} else if (Nodes[node1] != 0) {
					// Node1 設定済み
					if (distance) {
						// 偶数なら同じ色
						Nodes[node2] = Nodes[node1];
					} else {
						// 奇数なら違う色
						Nodes[node2] = Nodes[node1] % 2 == 0 ? Nodes[node1] - 1 : Nodes[node1] + 1;
					}
				} else if (Nodes[node2] != 0) {
					// Node2 設定済み
					if (distance) {
						// 偶数なら同じ色
						Nodes[node1] = Nodes[node2];
					} else {
						// 奇数なら違う色
						Nodes[node1] = Nodes[node2] % 2 == 0 ? Nodes[node2] - 1 : Nodes[node2] + 1;
					}

				} else {
					// Node1 Node2 未定
					if (distance) {
						// 偶数なら同じ色
						Nodes[node1] = c1;
						Nodes[node2] = c1;
					} else {
						// 奇数なら違う色
						Nodes[node1] = c1;
						Nodes[node2] = c2;
					}
					c1 += 2;
					c2 += 2;
				}
			}
			for (int i = 0; i < Nodes.Length; i++) {
				Console.WriteLine(Nodes[i] % 2);
			}
		}

		static void SwapColor(int color)
		{
			int c1, c2;
			if (color % 2 != 0) {
				c1 = color;
				c2 = color + 1;
			} else {
				c1 = color - 1;
				c2 = color;
			}
			for (int i = 0; i < Nodes.Length; i++) {
				if (Nodes[i] == c1) {
					Nodes[i] += 1;
				} else if (Nodes[i] == c2) {
					Nodes[i] -= 1;
				}
			}
		}
	}
}