let () =
    let main () =
        let n, u, v = Scanf.scanf "%d %d %d" (fun n u v -> n, u - 1, v - 1) in
        let ab = Array.init (n - 1) (fun _ -> Scanf.scanf " %d %d" (fun a b -> a - 1, b - 1)) in
        let nei = Array.make n [] in
        Array.iter (fun (a, b) -> nei.(a) <- b :: nei.(a); nei.(b) <- a :: nei.(b)) ab;
        let dist_aoki = Array.make n (-1) in
        let rec loop dist next = function
            | [] -> if next = [] then dist else loop (dist + 1) [] next
            | hd :: tl ->
                    if dist_aoki.(hd) >= 0 then loop dist next tl else (
                        dist_aoki.(hd) <- dist;
                        let next = List.rev_append nei.(hd) next in
                        loop dist next tl
                    )
        in
        let _ = loop 0 [] [ v ] in
        let rec loop dist next = function
            | [] -> if next = [] then dist else loop (dist + 1) [] next
            | hd :: tl ->
                    if dist_aoki.(hd) = dist then loop dist next tl else
                    let next = List.fold_left (fun next v ->
                        if dist_aoki.(v) <= dist then next else (v :: next)) next nei.(hd) in
                    loop dist next tl
        in
        let takahashi_max = loop 0 [] [ u ] in
        Printf.printf "%d\n" takahashi_max
    in
    main ()