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 < td
    max_v = v
    max_d = td
  end
end

diff = aoki_min[max_v] - takahashi_min[max_v]

a = 1
b = diff + 1
ans = max_d

if (a - b).abs == 1
  puts ans
  exit
end

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

  break if a == b

  b -= 1
  ans += 1

  break if a == b
end

puts ans
