let () = Scanf.scanf "%d\n" @@ fun n ->
  let es = Array.make n [] in
  for i = 0 to n - 2 do
    Scanf.scanf "%d %d %d\n" @@ fun u v w ->
      es.(u - 1) <- (v - 1, w) :: es.(u - 1);
      es.(v - 1) <- (u - 1, w) :: es.(v - 1)
  done;
  let colours = Array.make n None in
  let rec visit c v =
    match colours.(v) with
    | Some _ -> ()
    | None ->
        colours.(v) <- Some c;
        List.iter (fun (u, w) -> visit (c lxor (w land 1)) u) es.(v) in
  visit 0 0;
  Array.iter (function
    | None -> ()
    | Some c -> Printf.printf "%d\n" c) colours