n,u,v = gets.split.map(&:to_i)
road = Array.new(n+1){[]}

(n-1).times do 
    a,b = gets.split.map(&:to_i)
    road[a] << b
    road[b] << a
end

if road[u] == [v]
    puts 0
    exit
end

taka = Array.new(n+1,nil)
taka[u] = 0
queue = [u]
while x = queue.shift
    road[x].each do |e|
        next if taka[e]
        taka[e] = taka[x] + 1
        queue << e
    end
end
taka[u] = 2

aoki = Array.new(n+1,nil)
aoki[v] = 0
queue = [v]
while x = queue.shift
    road[x].each do |e|
        next if aoki[e]
        aoki[e] = aoki[x] + 1
        queue << e
    end
end

ans = Array.new(n+1,false)
max = 0
queue = [u]
while x = queue.shift
    road[x].each do |e|
        next if ans[e]
        ans[e] = true

        if road[e].size == 1
            m = taka[e] + (aoki[e] - taka[e]) / 2
            max = m if max < m
        else
            if taka[e] < aoki[e]
                queue << e
            end
        end
    end
end

p max