let () = Scanf.scanf "%d\n" @@ fun n ->
  let es = Array.make n [] in
  for i = 0 to n - 2 do
    Scanf.scanf "%d %d\n" @@ fun a b ->
      es.(a - 1) <- (b - 1, i) :: es.(a - 1);
      es.(b - 1) <- (a - 1, i) :: es.(b - 1)
  done;
  let colours = Array.make (n - 1) 0 in
  let visited = Array.make n false in
  let rec solve s v =
    visited.(v) <- true;
    ignore
      (List.fold_left (fun colour (u, i) ->
        let rec skip colour =
          if List.mem colour s then skip (colour + 1) else colour in
        let colour = skip colour in
        if visited.(u)
        then colour
        else begin
          colours.(i) <- colour;
          solve [colour] u;
          colour + 1
        end) 1 es.(v)) in
  solve [] 0;
  Printf.printf "%d\n" (Array.fold_left max min_int colours);
  Array.iter (Printf.printf "%d\n") colours

