from sys import setrecursionlimit
setrecursionlimit(10101)

N, u, v = map(int, input().split())
u -= 1
v -= 1
table = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    table[a].append(b)
    table[b].append(a)

depthu = [-1] * (N)
depthu[u] = 0
depthv = [-1] * (N)
depthv[v] = 0

def dfs_depth(p, depth):
    for q in table[p]:
        if depth[q] == -1:
            depth[q] = depth[p] + 1
            dfs_depth(q, depth)

dfs_depth(v, depthv)
dfs_depth(u, depthu)

p = [i for i in range(1, N-1) if depthu[i] >= depthv[i] + 2]
if p:
    print(max(depthu[i] + (depthu[i] - depthv[i]) // 2 for i in p))
else:
    print(depthv[u] // 2)
