N,u,v = gets.split.map(&:to_i)
G = Array.new(N + 1){ [] }
(1 ... N).each do
  a,b = gets.split.map(&:to_i)
  G[a] << b
  G[b] << a
end

def bfs(s, distance)
  used = Array.new(N + 1)
  q = [] 
  q << [s, 0]
  used[s] = true
  
  until q.empty?
    u,d = q.shift
    distance[u] = d

    G[u].each do |v|
      unless used[v]
        used[v] = true
        q << [v, d + 1]
      end
    end
    
  end
end

T = Array.new(N + 1, Float::INFINITY)
A = Array.new(N + 1, Float::INFINITY)

bfs(u, T)
bfs(v, A)

l = (1 .. N).max_by{|i| G[i].size == 1 && T[i] < A[i] ? A[i] : -Float::INFINITY }
puts A[l] - 1
