let rec fix f x = f (fix f) x
module Mi = Map.Make(struct type t = int let compare = (-) end)
module Mii = Map.Make(struct type t = int * int let compare = compare end)

let () =
  Scanf.scanf "%d" @@ fun n ->
  let gr, em = (1, Mi.empty, Mii.empty) |> fix @@ fun f (i, gr, em) ->
    if i >= n then (gr, em) else 
    Scanf.scanf " %d %d" @@ fun a b ->
      let gr = gr |> Mi.add a (b :: (try Mi.find a gr with _ -> []))
                  |> Mi.add b (a :: (try Mi.find b gr with _ -> []))
      and em = em |> Mii.add (a, b) i
      in f (i+1, gr, em)
  in
  let em = (1, 0, 0, Mi.empty) |> fix @@ fun f (u, c, p, a) ->
    Mi.find u gr |> List.fold_left (fun (i, a) v ->
      if v = p then (i, a) else
      let i = if i = c then i+1 else i in
      let k = min u v, max u v in
      let a = Mi.add (Mii.find k em) i a in
      (i+1, f (v, i, u, a))) (1, a)
    |> snd
  in
  Printf.printf "%d\n" (Mi.fold (fun _ v a -> max v a) em 0);
  Mi.iter (fun _ -> Printf.printf "%d\n") em

