n, uplus, vplus = map(int, input().split())
u, v = uplus-1, vplus-1
adj = [[] for _ in range(n)]
for _ in range(n-1):
  aplus, bplus = map(int, input().split())
  a, b = aplus-1, bplus-1
  adj[a].append(b)
  adj[b].append(a)

u_dist = [n] * n
u_dist[u] = 0
stack = [u]
while stack:
  vertex = stack.pop()
  for nxt in adj[vertex]:
    if u_dist[nxt] == n:
      u_dist[nxt] = u_dist[vertex] + 1
      stack.append(nxt)

v_dist = [n] * n
v_dist[v] = 0
stack = [v]
leaves = []
while stack:
  vertex = stack.pop()
  isleaf = True
  for nxt in adj[vertex]:
    if u_dist[nxt] == n:
      u_dist[nxt] = u_dist[vertex] + 1
      stack.append(nxt)
      isleaf = False
  if isleaf:
    leaves.append(vertex)

max_depth = 0
for leaf in leaves:
  depth = v_dist[leaf]
  if u_dist[leaf] < depth and max_depth < depth:
    max_depth = depth
    
print(max_depth - 1)