N, U, V = gets.split.map(&:to_i)

E = Hash.new { |h, k| h[k] = [] }

(N - 1).times do
  a, b = gets.split.map(&:to_i)

  E[a] << b
  E[b] << a
end

aoki_min = Hash.new(Float::INFINITY)
queue = [[V, 0]]

until queue.empty?
  v, dist = queue.shift

  next if aoki_min[v] <= dist
  aoki_min[v] = dist

  E[v].each do |u|
    queue << [u, dist + 1]
  end
end

takahashi_min = Hash.new(Float::INFINITY)
queue = [[U, 0]]

until queue.empty?
  v, dist = queue.shift

  next if takahashi_min[v] <= dist
  takahashi_min[v] = dist

  E[v].each do |u|
    queue << [u, dist + 1]
  end
end

max_v = -1
max_d = -1

(1..N).each do |v|
  ad = aoki_min[v]
  td = takahashi_min[v]

  next if ad <= td

  if max_d < ad
    max_v = ad
  end
end

ans = max_v - 1

def f(x)
  a = 1
  b = x + 1
  cnt = 0

  loop do
    if a == 1
      a += 1
    else
      a -= 1
    end

    break if a == b

    b -= 1
    cnt += 1

    break if a == b
  end

  cnt
end

puts ans
