#LCA0000088. Tô màu theo khoảng cách chẵn (Even Relation)
Bài tập thuộc lộ trình
Mục lục đề ⌄
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 vertices and positive integer edge lengths. Color each vertex either or 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: , followed by lines .
Output
Print lines. Line gives color or of vertex . Any valid coloring is accepted.
Subtasks
-
Subtask 1 (20 points): ; for every edge; ; edges form a tree có vertices.
-
Subtask 2 (30 points): ; for every edge; ; edges form a tree có vertices.
-
Subtask 3 (50 points): ; for every edge; ; edges form a tree có vertices.
Examples
Input
3
1 2 2
2 3 1
Output
0
0
1
Explanation
Vertices have equal colors because their distance is even (). Vertex has the opposite color because edge has odd length. Flipping every color also yields a valid answer.