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: Time Limit Exceeded)

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

(defmacro next-int ()
  '(read))

(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+))) ; 頂点の色。

      (dfs 0 color g +color-white+)

      (format t "~{~A~^~%~}~%" (coerce color 'list)))))

(defun dfs (now     ; 現在訪問している頂点
            color   ; 色を出力する配列
            g       ; 辺の接続先と長さの情報
            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 color g (mod (+ mod length) 2))))))

;; 各頂点についてその接続情報を収めた表 g を生成して返す。
;; g[頂点番号][各辺][+edge-other-vertex+] = 辺の長さ
;; g[頂点番号][各辺][+edge-length+] = 接続先の頂点
(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)