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 edge = [| for x in [0..n] -> [||] |]
    for i in [1..n-1] do
        let ab = Console.ReadLine().Split(' ') |> Array.map int
        let a, b = ab.[0], ab.[1]
        edge.[a] <- Array.append edge.[a] [|b|]
        edge.[b] <- Array.append edge.[b] [|a|]

    let p = Array.zeroCreate (n + 1)
    p.[u] <- -1

    let rec dpath pos =
        for ne in edge.[pos] do
            if p.[ne] = 0 then
                p.[ne] <- pos
                dpath ne
        ()

    dpath u

    let rec cpath pos =
        if pos = u then [|u|]
        else Array.append [|pos|] (cpath p.[pos])
        
    let path = cpath v
    let len = path.Length - 1

    let start, wall = path.[len / 2 + 1], path.[len / 2]
    let depth = Array.zeroCreate (n + 1)
    depth.[start] <- 1
    depth.[wall] <- -1

    let rec dep pos =
        for ne in edge.[pos] do
            if depth.[ne] = 0 then
                depth.[ne] <- depth.[pos] + 1
                dep ne
        ()

    dep start
    printfn "%d" (len / 2 + (Array.max depth) - 1)

    0
