import strutils, sequtils

const N_MAX = 100000
# const N_MAX = 5

var
  input = stdin.readline.split.map(parseint)
  n = input[0]
  u = input[1]
  v = input[2]
  arr : array[1..N_MAX, array[1..N_MAX, int]]

for i in 1..n:
  for j in 1..n:
    arr[i][j] = high(int32)

for i in 1..n-1:
  let input = stdin.readline.split.map(parseint)
  arr[input[0]][input[1]] = 1
  arr[input[1]][input[0]] = 1

# warshall
for i in 1..n:
  for j in 1..n:
    for k in 1..n:
      if arr[j][k] > arr[j][i] + arr[i][k]:
        arr[j][k] = arr[j][i] + arr[i][k]
        arr[k][j] = arr[j][k]

# echo arr

proc takahashi_choice () : int =
  var
    opponent_choice: tuple[id: int, min: int] = (id: 0, min: high(int))
    my_choice: tuple[id: int, max: int] = (id: 0, max: -1)
  for i in 1..n:
    if (arr[v][i] == 1) and (arr[i][u] < opponent_choice.min):
      opponent_choice = (id: i, min: arr[i][u])
  for i in 1..n:
    if (arr[u][i] == 1) and (arr[i][opponent_choice.id] > my_choice.max) and (i != v):
      my_choice = (id: i, max: arr[i][opponent_choice.id])
  if my_choice.id == 0:
    return v
  return my_choice.id

proc aoki_choice () : int =
  var
    opponent_choice: tuple[id: int, max: int] = (id: 0, max: -1)
    my_choice: tuple[id: int, min: int] = (id: 0, min: high(int))
  for i in 1..n:
    if (arr[u][i] == 1) and (arr[i][v] > opponent_choice.max) and (i != v):
      opponent_choice = (id: i, max: arr[i][v])
  if opponent_choice.id == 0:
    opponent_choice = (id: v, max: 0)
  for i in 1..n:
    if (arr[u][i] == 1) and (arr[i][opponent_choice.id] < my_choice.min):
      my_choice = (id: i, min: arr[i][opponent_choice.id])
  return my_choice.id

var count : int
while true:
  # echo "u: " & $u & " v: " & $v
  if u == v:
    break
  u = takahashi_choice()
  # echo "u: " & $u & " v: " & $v
  if u == v:
    break
  v = aoki_choice()
  count += 1

echo count
