open Printf open Scanf
open Array

let () = scanf " %d" @@ fun n ->
  let edges = make n [] in
  let p = init (n-1) (fun _ -> scanf " %d %d %d" @@ fun u v w ->
    edges.(u-1) <- (v-1,w) :: edges.(u-1);
    edges.(v-1) <- (u-1,w) :: edges.(v-1);
    w,u
  )
  |> fold_left (fun u (w,p) ->
    if w mod 2 = 1 then p else u
  ) 0
  in
  let color = make n 2 in
  let rec dfs i c =
    if color.(i) <> 2 then ()
    else (
      color.(i) <- c;
      List.iter (fun (j,w) ->
        if w mod 2 = 0 then dfs j c
        else dfs j (1-c)
      ) edges.(i);
    )
  in dfs p 0;
  iter (printf "%d\n") color
