n, u, v = gets.split.map(&:to_i)
edges = []
(n - 1).times { edges << gets.split.map(&:to_i) }
graph = Array.new(n + 1) { Array.new }
# 無向グラフなので両始点のグラフに入れる
edges.each do |f, t|
  graph[f] << [f, t]
  graph[t] << [t, f]
end

takahashi_dist = []
takahashi_dist[u] = 0
takahashi_queue = [[u, u, 0]]
until takahashi_queue.empty?
  from, to, cost = takahashi_queue.shift
  graph[to].each do |f, t|
    # 逆流しないようにする（両方のグラフに入れているので必ず1つ該当する）
    next if t == from
    takahashi_dist[t] = cost + 1
    takahashi_queue << [f, t, cost + 1]
  end
end
takahashi_dist.shift

aoki_dist = []
aoki_dist[v] = 0
aoki_queue = [[v, v, 0]]
until aoki_queue.empty?
  from, to, cost = aoki_queue.shift
  graph[to].each do |f, t|
    # 逆流しないようにする（両方のグラフに入れているので必ず1つ該当する）
    next if t == from
    aoki_dist[t] = cost + 1
    aoki_queue << [f, t, cost + 1]
  end
end
aoki_dist.shift

ans = []
n.times do |i|
  if takahashi_dist[i] < aoki_dist[i]
    ans << aoki_dist[i] - 1
  end
end
puts ans.max
