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 = Array2D.zeroCreate (n + 1) (n + 1)
    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, b] <- 1
            mat.[b, a] <- 1
            edge (i + 1)
    edge 1
    let rec path pos count history prev =
        let neighbor = Array.filter (fun i -> mat.[pos, i] = 1 && i <> prev) [|1..n|]
        if pos = v then (count, Array.append history [|v|])
        else if neighbor.Length = 0 then (0, history)
        else
            let res = [| for ne in neighbor -> path ne (count + 1) (Array.append history [|pos|]) pos |]
            Array.max res
    let l, p = path u 0 [||] -1
    let ans0 = l / 2
    let rec dep pos prev count =
        let neighbor = Array.filter (fun i -> mat.[pos, i] = 1 && i <> prev && i <> p.[(l-1) / 2 + 1]) [|1..n|]
        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
