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 Common Lisp (SBCL 1.1.14) (judge verdict: Runtime Error)

(defconstant +color-unknown+ -1)
(defconstant +color-white+ 0)
(defconstant +color-black+ 1)

(defun solve ()
  (let*  ((n (next-int))                 ; 頂点の数
          ;; 根を除いて各頂点にはたった1つの親頂点があるので、辺の数は
          ;; 「頂点の数-1」になる。
          (from (make-array (1- n)))     ; 番号が小さいほうの頂点
          (to (make-array (1- n)))       ; 番号が大きいほうの頂点
          (w (make-array (1- n))))       ; 辺の長さ
    (loop for i below (1- n)
         do
         ;; 0ベース配列の添字にしたいので、各頂点番号をデクリメントしておく。
         (setf (aref from i) (1- (next-int)))
         (setf (aref to i) (1- (next-int)))
         (setf (aref w i) (next-int)))

    (let ((g (pack-wu n from to w))
          (color (make-array n :initial-element +color-unknown+))) ; 頂点の色。

      (labels ((dfs (now     ; 現在訪問している頂点
                     mod)    ; 現在の頂点の色(0 か 1)
                 (setf (aref color now) mod)
                 (loop for edge across (aref g now)
                    do
                      (destructuring-bind
                            (next-vertex length) edge
                        (when (= (aref color next-vertex) +color-unknown+)
                          (dfs next-vertex (mod (+ mod length) 2)))))))
        (dfs 0 +color-white+))

      (loop for i below n
           do
           (format t "~A~%" (aref color i))))))

(defun next-int ()
  (read))

;; 各頂点についてその接続情報を収めた表 g を生成して返す。
;; g[頂点番号][各辺] = (list 辺の長さ 接続先の頂点)
(defun pack-wu (n from to w)
  (let ((sup (length from)) ; 辺の数
        (g (make-array n))
        (p (make-array n :initial-element 0))) ; 各頂点の次数(接続している辺の数)

    ;; 各頂点の次数を数える。各辺は、2つの頂点の次数をそれぞれ1つずつ
    ;; 増やす。
    (loop for i below sup
       do
         (incf (aref p (aref from i)))
         (incf (aref p (aref to i))))

    (loop for i below n
       do
       ;; g[i] に頂点 i 接続している辺の情報を収める配列を割り当てる。
         (setf (aref g i) (make-array (aref p i))))

    ;; 各頂点の持つ辺の情報を配列の後ろから格納する。
    (loop for i below sup
       do
         (let ((v (aref from i))
               (u (aref to i))
               (len (aref w i)))

           (decf (aref p v))
           (setf (aref (aref g v) (aref p v)) (list u len))

           (decf (aref p u))
           (setf (aref (aref g u) (aref p u)) (list v len))))

    g))

(solve)