de = false
require 'set'
n,u,v = gets.chomp.split.map(&:to_i)
edges = {}
(n-1).times do |i|
  a, b= gets.chomp.split.map(&:to_i)
  edges[a] ||= Set.new
  edges[a].add b
  edges[b] ||= Set.new
  edges[b].add a
end
p edges if de

taka = [Set.new([u])]
aoki = [Set.new([v])]
taka_visited = Array.new(n+1,-1)
aoki_visited = Array.new(n+1,-1)
taka_visited[u] = 0
aoki_visited[v] = 0
turn = 0

until aoki.empty?
  p turn if de
  p ['taka', taka_visited] if de
  p ['aoki', aoki_visited] if de
  turn += 1
  taka_v = taka.shift
  taka_next = Set.new
  break_flg = false

  taka_v.each do |from|
    if edges[from].size == 1 # 行き先が一個の場合強制ターンする
      to = edges[from].first

      if aoki_visited[to] >= 0
        break_flg = true
        turn -= 1
        break
      end
      taka_visited[to] = turn.odd? ? -2 : -3
    else
      edges[from].each do |to|
        next if taka_visited[to] >= 0
        next if aoki_visited[to] >= 0
        taka_next.add to
        taka_visited[to] = turn
      end
    end
  end
  break if break_flg
  taka.push taka_next

  # -- Aoki
  aoki_v = aoki.shift
  aoki_next = Set.new
  aoki_v.each do |from|
    edges[from].each do |to|
      if taka_visited[to] == turn
        break_flg = true
        break
      elsif taka_visited[to] <= -2
        turn += 1 if (turn + taka_visited[to]).even?
        break_flg = true
        break
      end
      next if aoki_visited[to] >= 0
      aoki_next.add to
      aoki_visited[to] = turn
    end
  end
  break if break_flg
  aoki.push aoki_next
end

puts turn
