N,u,v=gets.split.map(&:to_i)
list=Array.new(N){Array.new}
(N-1).times do |i|
    a,b=gets.split.map(&:to_i)
    list[a-1].push(b-1)
    list[b-1].push(a-1)
end
visited=Array.new(N,false)
dist=Array.new(N,-1)
faint=Array.new(N,false)
stack=Array.new
stack.push(v-1)
until stack.empty?
    cur=stack.pop
    next if visited[cur]
    visited[cur]=true
    faint[cur]=true if cur==u-1
    ma=-1
    list[cur].each do |e|
        ma=ma<dist[e] ? dist[e] : ma
        faint[cur]=true if faint[e]
        stack.push(e)
    end
    dist[cur]=ma+1
end
res=0
N.times do |i|
    res=res<dist[i] ? dist[i] : res if faint[i]
end
p dist
puts res-1