n, u, v = gets.split.map(&:to_i)
nodes = Array.new(n + 1) { [] }
$stdin.read.split.each_slice(2) do |a, b|
  a = a.to_i
  b = b.to_i
  nodes[a] << b
  nodes[b] << a
end


def distance(nodes, start)
  ary = Array.new(nodes.size)
  ary[0] = -1

  q = [start]
  0.upto(Float::INFINITY) do |m|
    break if q.delete_if { |n| ary[n] }.empty?

    q = q.flat_map do |n|
      ary[n] = m
      nodes[n]
    end
  end

  ary
end


u_dist = distance(nodes, u)
v_dist = distance(nodes, v)

m = u_dist.zip(v_dist).map { |u, v| u < v ? v - 1 : 0 }.max
puts m
