import heapq
INFTY = 10**6
N,u,v = map(int,input().split())
G = {i:[] for i in range(1,N+1)}
for _ in range(N-1):
    a,b = map(int,input().split())
    G[a].append(b)
    G[b].append(a)
dist1 = [INFTY for _ in range(N+1)]
hist = [0 for _ in range(N+1)]
heap = [(0,u)]
dist1[u] = 0
hist[u] = 1
while heap:
    d,x = heapq.heappop(heap)
    if d>dist1[x]:continue
    hist[x]=1
    for y in G[x]:
        if hist[y]==0 and dist1[y]>d+1:
            dist1[y] = d+1
            heapq.heappush((d+1,y))
dist2 = [INFTY for _ in range(N+1)]
hist = [0 for _ in range(N+1)]
heap = [(0,v)]
dist2[v] = 0
hist[v] = 1
while heap:
    d,x = heapq.heappop(heap)
    if d>dist2[x]:continue
    hist[x]=1
    for y in G[x]:
        if hist[y]==0 and dist2[y]>d+1:
            dist2[y] = d+1
            heapq.heappush((d+1,y))
cmax = 0
for i in range(1,N+1):
    if dist1[i]<dist2[i]:
        cmax = max(cmax,dist2[i])
print(cmax-1)