from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n,u,v = inpl()
u -= 1
v -= 1
g = [[] for i in range(n)]
for i in range(n-1):
    a,b = inpl()
    a -= 1
    b -= 1
    g[a].append(b)
    g[b].append(a)
ucost = [INF] * n
vcost = [INF] * n

def udfs(node,c):
    for next in g[node]:
        if ucost[next] == INF:
            ucost[next] = c + 1
            udfs(next,ucost[next])
 
udfs(u,0)
def vdfs(node,c):
    for next in g[node]:
        if vcost[next] == INF:
            vcost[next] = c + 1
            vdfs(next,vcost[next])
vdfs(v,0)
# print(ucost,vcost)
res = 0
seen = [-INF] * n
seen[u] = ucost[v]
def dfs(node,nsa):
    for new in g[node]:
        if seen[new] != -INF:
            continue
        tmp = nsa
        if vcost[new] < vcost[node]:
            tmp -= 2
        if tmp <= 1:
            continue
        seen[new] = tmp
        dfs(new,tmp) 
dfs(u,ucost[v])
res = -INF
for i in range(n):
    res = max(res,seen[i] + ucost[i])
print(max(0,res-3))