open System

[<EntryPoint>]
let main argv =
    let input = Console.ReadLine().Split(' ') |> Array.map int
    let n, u, v = input.[0], input.[1], input.[2]
    let mat = [| for x in [0..n] -> [||] |]

    let rec edge i =
        if i = n then ()
        else
            let ab = Console.ReadLine().Split(' ') |> Array.map int
            let a, b = ab.[0], ab.[1]
            mat.[a] <- Array.append mat.[a] [|b|]
            mat.[b] <- Array.append mat.[b] [|a|]
            edge (i + 1)
    edge 1

    let pmemo = Array.zeroCreate (n + 1)
    let rec dpath pos prev =
        pmemo.[pos] <- prev
        for ne in mat.[pos] do
            if pmemo.[ne] = 0 then dpath ne pos
        ()
    dpath u -1

    let rec path pos =
        if pos = u then [|u|]
        else Array.append (path pmemo.[pos]) [|pos|]

    let p = path v
    let l = p.Length - 1
    let ans0 = l / 2
    
    let rec dep pos prev count =
        let neighbor = Array.filter (fun i -> i <> prev && i <> p.[(l-1) / 2 + 1]) mat.[pos]
        if neighbor.Length = 0 then count
        else
            let res = [| for ne in neighbor -> dep ne pos (count + 1) |]
            Array.max res
    let ans1 = dep p.[(l-1) / 2] -1 0

    printfn "%d" (ans0 + ans1)
    0
