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

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

max = v
1.upto(n) do |i|
    next if road[i].size != 1 || taka[i] > aoki[i]
    max = i if aoki[max] < aoki[i]
end

puts taka[max] + (aoki[max] - taka[max] - 1)