PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#LCA0000088. Tô màu theo khoảng cách chẵn (Even Relation)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Tô màu theo khoảng cách chẵn (Even Relation)

Even Relation

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

A tree has nn vertices and positive integer edge lengths. Color each vertex either 00 or 11 so that every pair of vertices sharing the same color has an even weighted distance between them. A solution always exists, and any valid coloring is accepted. Both colors need not appear.

Input

First line: nn, followed by n−1n-1 lines u,v,wu,v,w.

Output

Print nn lines. Line vv gives color 00 or 11 of vertex vv. Any valid coloring is accepted.

Subtasks

  • Subtask 1 (20 points): 1≤n≤351\le n\le 35; 1≤u<v≤n1\le u<v\le n for every edge; 1≤w≤1091\le w\le10^9; edges form a tree có nn vertices.

  • Subtask 2 (30 points): 1≤n≤12001\le n\le 1200; 1≤u<v≤n1\le u<v\le n for every edge; 1≤w≤1091\le w\le10^9; edges form a tree có nn vertices.

  • Subtask 3 (50 points): 1≤n≤1000001\le n\le 100000; 1≤u<v≤n1\le u<v\le n for every edge; 1≤w≤1091\le w\le10^9; edges form a tree có nn vertices.

Examples

Input

3
1 2 2
2 3 1

Output

0
0
1

Explanation

Vertices 1,21,2 have equal colors because their distance is even (22). Vertex 33 has the opposite color because edge 2−32-3 has odd length. Flipping every color also yields a valid answer.