import copy
import sys
sys.setrecursionlimit(10**9)

def dfs(G, v, p, d):
    depth[v] = d
    for nv in G[v]:
        if nv == p:
            continue
        dfs(G, nv, v, d+1)


n, T, A = map(int,input().split())
T, A = T-1, A-1
g = [[] for _ in range(n)]
for i in range(n-1):
    x, y = map(int,input().split())
    x, y = x-1, y-1
    g[x].append(y)
    g[y].append(x)

depth = [0]*n
GT = copy.deepcopy(g)
GT[T].append(-1)
root = T
dfs(GT, root, -1, 0)
dt = depth.copy()

depth = [0]*n
GA = copy.deepcopy(g)
GA[A].append(-1)
root = A
dfs(GA, root, -1, 0)
da = depth.copy()

def dfs2(GT, v, p):
    for nv in GT[v]:
        if nv == p:
            continue
        if dt[nv] <= da[nv]:
            maxd[0] = max(maxd[0], da[nv])
        else:
            continue
        dfs2(GT, nv, v)


maxd = [da[T]]
root = T
dfs2(GT, root, -1)
print(maxd[0]-1)