N,u,v=gets.split.map(&:to_i)
u-=1;v-=1
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
dp=Array.new(N,-1) #dp[i]:=ノードiの親
stack=Array.new
visited=Array.new(N,false)
stack.push(v)
until stack.empty?
    pres=stack.pop
    next if visited[pres]
    visited[pres]=true
    list[pres].each do |e|
        dp[e]=pres if dp[e]==-1
        stack.push(e)
    end
end
dp[v]=-1
path=Array.new
path.push(u)
while true
    break if dp[path[0]]==-1
    path.unshift(dp[path[0]])
end

conf=path[(path.size-1)/2]
if path.size==2
    list[conf]=[path[(path.size-1)/2+1]]
else
    list[conf]=[path[(path.size-1)/2+1],path[(path.size-1)/2-1]]
end
dp=Array.new(N,-1) #dp[i]:=u->iの距離
valid=Array.new(N,false)
stack=[v]
until stack.empty?
    pres=stack.pop
    next if dp[pres]!=-1
    d=-1
    valid[pres]=true if pres==conf
    list[pres].each do |e|
        d=d<dp[e] ? dp[e] : d
        valid[pres]=true if valid[e]
        stack.push(e)
    end
    dp[pres]=d+1
end
res=0
N.times do |i|
    res=res<dp[i] ? dp[i] : res if valid[i]
end
puts res-1