import sys
from collections import defaultdict as dd
import heapq
input = sys.stdin.readline
N, u, v = map(int, input().split())
e = dd(list)
for _ in range(N - 1):
  a, b = map(int, input().split())
  e[a].append((b, 1))
  e[b].append((a, 1))
class dijkstra:
  def __init__(self, n, e):
    self.e = e
    self.n = n
  def path(self, s, t):
    d = [float("inf")] * (self.n + 1)
    vis = set()
    d[s] = 0
    h = [s]
    while not t in vis and len(h):
      v = heapq.heappop(h)
      v1 = v % (10 ** 6)
      v0 = v // (10 ** 6)
      if v1 in vis: continue
      vis.add(v1)
      for p in self.e[v1]:
        d[p[0]] = min(d[p[0]], d[v1] + p[1])
        if p[0] in vis: continue
        heapq.heappush(h, d[p[0]] * (10 ** 6) + p[0])
    return d
d = dijkstra(N, e)
p = d.path(v, 0)
pp = d.path(u, 0)
#print(p)
#print(pp)
res = -1
ee = dd(list)
for k in e.keys():
  for x in e[k]:
    if p[x[0]] > pp[x[0]]:
      ee[k].append((x[0], 1))
dd = dijkstra(N, ee)
ppp = dd.path(u, 0)
#print(ppp)
t = 0
for i in range(1, N + 1):
  if ppp[i] != float("inf"):
    if ppp[i] > res:
      res = ppp[i]
      if ppp[i] + 1 < p[i]: res = p[i]
      t = i
for x in e[t]:
  if p[x[0]] == pp[x[0]]: 
    res = ppp[t]
    res += 1
    break
print(res)