let () =
  Scanf.scanf "%d" @@ fun n ->
  let g = Array.init n (fun _ -> []) in
  for _ = 2 to n 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 (-1) in
  let rec dfs u c p =
    cs.(u) <- c;
    g.(u) |> List.iter (fun (v, w) -> if p <> v then dfs v ((c + w) mod 2) u)
  in
  dfs 0 0 (-1);
  Array.iter (Printf.printf "%d\n") cs;
