
from collections import deque
N, u, v = map(int, input().split())
u, v = u-1, v-1
AB = [list(map(int, input().split())) for a in range(N-1)]

G = [[0 for b in range(N)] for a in range(N)]
D = [[0 for b in range(N)] for a in range(N)]


for ab in AB:
  G[ab[0]-1][ab[1]-1] = 1
  G[ab[1]-1][ab[0]-1] = 1

def bfs(current, goal):
  if D[current][goal] > 0:
    return D[current][goal]
  q = deque([[current, 0]])
  memo = [0 for a in range(N)]
  while q:
    startcost = q.popleft()
    start = startcost[0]
    cost = startcost[1]
    if start == goal:
      D[current][goal] = cost
      D[goal][current] = cost
      return cost
    for i in range(N):
      if G[start][i] == 1 and memo[i] == 0:
        q.append([i, cost + 1])
        memo[i] = 1
  

distances = [0]
for i in range(N):
  aoki = bfs(i, v)
  takahashi = bfs(i, u)
  if aoki > takahashi:
    distances.append(aoki)

print(max(distances)-1)

