let () = Scanf.scanf "%d %d %d\n" @@ fun n u v ->
  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 :: es.(a - 1);
      es.(b - 1) <- a - 1 :: es.(b - 1)
  done;
  let height = Array.make n 0 in
  let trace = Array.make n [] in
  let visited = Array.make n false in
  let rec visit tr u =
    if not visited.(u) then begin
      visited.(u) <- true;
      trace.(u) <- u :: tr;
      height.(u) <- 1 +
        List.fold_left (fun acc v ->
          visit (u :: tr) v;
          max acc height.(v)) 0 es.(u)
    end in
  visit [] (u - 1);
  let d = List.length trace.(v - 1) in
  List.iter (Printf.printf "%d ") trace.(v - 1);
  print_newline ();
  let u' = List.nth trace.(v - 1) ((d + 1) / 2) in
  let v' = List.nth trace.(v - 1) ((d - 1) / 2) in
  Printf.printf "%d\n" @@
  (d - 1) / 2
  + List.fold_left (fun acc w -> max acc @@
      if w = v' then min_int
      else if height.(u') < height.(w) then (d - 2) / 2
      else height.(w)) 0 es.(u')
