(* O(n) *)
Scanf.scanf " %d" @@ fun n ->
  let g = Array.make n [] in
  for _ = 1 to n - 1 do
    Scanf.scanf " %d %d %d" @@ fun u v w ->
      let u, v = u - 1, v - 1 in
      g.(u) <- (v, w mod 2) :: g.(u);
      g.(v) <- (u, w mod 2) :: g.(v);
  done;
  let cs = Array.make n 0 in
  let rec dfs v p c =
    cs.(v) <- c;
    let f (v2, w) = if v2 <> p then dfs v2 v @@ c lxor w in List.iter f g.(v) in
  dfs 0 (-1) 0;
  cs |> Array.iter @@ Printf.printf "%d\n"