local mma = math.max
local n = io.read("*n")
local t_pos, a_pos = io.read("*n", "*n")

local edge = {}
local t_asked, a_asked = {}, {}
local t_len, a_len = {}, {}
for i = 1, n do
  edge[i] = {}
  t_asked[i], a_asked[i] = false, false
  t_len[i], a_len[i] = 0, 0
end
for i = 1, n - 1 do
  local x, y = io.read("*n", "*n")
  table.insert(edge[x], y)
  table.insert(edge[y], x)
end

local tasks = {t_pos}
while 0 < #tasks do
  local src = tasks[#tasks]
  table.remove(tasks)
  t_asked[src] = true
  for i = 1, #edge[src] do
    local dst = edge[src][i]
    if not t_asked[dst] then
      t_len[dst] = t_len[src] + 1
      table.insert(tasks, dst)
    end
  end
end
tasks = {a_pos}
while 0 < #tasks do
  local src = tasks[#tasks]
  table.remove(tasks)
  a_asked[src] = true
  for i = 1, #edge[src] do
    local dst = edge[src][i]
    if not a_asked[dst] then
      a_len[dst] = a_len[src] + 1
      table.insert(tasks, dst)
    end
  end
end

tasks = {t_pos}
for i = 1, n do
  t_asked[i] = false
end
local cand = 0
while 0 < #tasks do
  local src = tasks[#tasks]
  table.remove(tasks)
  t_asked[src] = true
  cand = mma(cand, a_len[src])
  for i = 1, #edge[src] do
    local dst = edge[src][i]
    if not t_asked[dst] then
      if t_len[dst] < a_len[dst] then
        table.insert(tasks, dst)
      end
    end
  end
end
print(cand - 1)
