from heapq import heappop, heappush
from collections import deque
n , U , V = map(int,input().split())
U -= 1
V -= 1
mp2 = []
route = [[] for i in range(n)]
for i in range(n-1):
    a , b = map(lambda x:int(x)-1,input().split())
    mp2.append((a,b,1))
    mp2.append((b,a,1))
    route[a].append(b)
    route[b].append(a)
inf=float('inf')
d=[inf for i in range(n)]
d[V] = 0
prev=[None]*n
p=dict()
for i,j,k in mp2: p[i]=p.get(i,[])+[(j,k)]

q=[]
heappush(q,(d[V],V))
while q:
    du, u = heappop(q)
    if d[u]<du: continue
    for v,weight in p.get(u,[]):
        alt=du+weight
        if d[v]>alt:
            d[v]=alt
            prev[v]=u
            heappush(q, (alt,v))
p=[U]
while prev[p[-1]]!=None: p.append(prev[p[-1]])
aida = -(-len(p)//2)-1
t = p[-(-len(p)//2)]

d = deque()
d.append(t)
visit = [0 for i in range(n)]
for i in range(len(p)):
    if p[i] == t:
        break
    visit[p[i]] = -inf
visit[t] = 0

while d:
    now = d.popleft()
    for i in route[now]:
        if visit[i] == 0:
            visit[i] = visit[now] + 1
            d.append(i)
nige = max(visit)
if nige == 0:
    print(len(p)-2)
else:
    print(aida+nige-1)