let rec fix f x = f (fix f) x

let _ =
  Scanf.scanf "%d %d %d" @@ fun n u v ->
  let a = Array.init (n+1) (fun _ -> []) in
  for i = 1 to n-1 do
    Scanf.scanf " %d %d" @@ fun x y ->
      a.(x) <- y :: a.(x);
      a.(y) <- x :: a.(y);
  done;
  let rec mark arr u d =
    arr.(u) <- d;
    List.iter (fun v -> if arr.(v) > n then mark arr v (d+1)) a.(u)
  in
  let d2 =
    let arr = Array.make (n+1) (n+1) in
    mark arr v 0; arr
  in
  fix (fun f i ans -> if i > n then ans else f (i+1) (max ans (d2.(i)-1))) 1 0
  |> Printf.printf "%d\n"
        

