n, takahashi, aoki = gets.split.map(&:to_i)

graph = Array.new(n + 1) { Array.new }

(n-1).times do
  a, b = gets.split.map(&:to_i)
  graph[a] << b
  graph[b] << a
end

height = Array.new(n + 1, nil)
parent = Array.new(n + 1, nil)

queue = [[aoki, 0]]

while !queue.empty?
  top, h = queue.shift
  height[top] = h

  graph[top].each do |child|
    if height[child] == nil
      queue.push([child, h + 1])
      parent[child] = top
    end
  end
end

t = takahashi
ah = height[aoki]
th = height[takahashi]

while (th - ah) > 2
  t = parent[t]
  ah += 1
  th -= 1
end

# 頂点 t の下にある、最も深い頂点を探す
mx = 0
queue = [t]

while !queue.empty?
  top = queue.shift
  mx = [mx, height[top]].max

  graph[top].each do |child|
    if height[child] > height[top]
      queue.push(child)
    end
  end
end

p mx - 1
