type edge = {a: int; b: int; i: int}

let degrees edges =
  let rec helper edges acc =
    match edges with
    | [] -> acc
    | {a=a; b=b} :: rst ->
      acc.(a) <- acc.(a) + 1;
      acc.(b) <- acc.(b) + 1;
      helper rst (acc) in
  helper edges (Array.make ((List.length edges) + 1) 0)
;;

let solve n edges =
  let k =
    let rec find_max l i m =
      if i == Array.length l then m
      else if l.(i) > m then find_max l (i+1) l.(i)
      else find_max l (i+1) m in
    find_max (degrees edges) 0 0 in
  let p = Array.make n 0 in
  let cs = Array.make (n-1) 0 in
  let rec choose_color es prev cnt =
    match es with
    | [] -> cs
    | e :: rst ->
      let cnt = if e.a == prev then cnt else 0 in
      let color = if e.a == 0 then cnt
        else if cnt < p.(e.i) then cnt else cnt + 1 in
      p.(e.a) <- color; cs.(e.i) <- color;
      choose_color rst e.a (cnt+1) in
  (k, choose_color edges 0 0)
;;

let read () =
  let n = read_int () in
  let rec read_edges i acc =
    if i == n-1 then acc else
      let input = Str.split (Str.regexp " ") (read_line ()) in
      let a::b::[] = List.map int_of_string input in
      let edge = {a=a-1; b=b-1; i=i} in
      read_edges (i+1) (edge :: acc) in
  let edges = List.sort (fun e1 e2 -> e1.a - e2.a) (read_edges 0 []) in
  (n, edges) in
let print k colors =
  print_endline (string_of_int k);
  for i = 0 to ((Array.length colors) - 1) do
    print_endline (string_of_int (colors.(i) + 1))
  done in
let n, edges = read() in
let k, colors = solve n edges in
print k colors
