n, u, v = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n - 1)]

n, u, v = 9, 6, 1
ab = [[1,2],[2,3],[3,4],[4,5],[5,6],[4,7],[7,8],[8,9]]

from collections import defaultdict
graph = defaultdict(list)
for i in range(n - 1):
    a = ab[i][0] - 1
    b = ab[i][1] - 1
    graph[a].append(b)
    graph[b].append(a)
u -= 1
v -= 1

visited = [0] * n
def dfs(cur, target, path):
    # print(cur, path)
    visited[cur] = 1
    if cur == target:
        return path
    else:
        for v in graph[cur]:
            if not visited[v]:
                p = dfs(v, target, path + [v])
                if p:
                    return p

path = dfs(v, u, [v])
# print(path)

_path_aoki = path[:len(path) // 2]
path_aoki = [0] * n
for i in range(len(_path_aoki)):
    path_aoki[_path_aoki[i]] = 1

# 最も遠い点
paths = []
visited = [0] * n
def dfs2(cur, path):
    visited[cur] = 1
    f = True
    for v in graph[cur]:
        if not visited[v] and not path_aoki[v]:
            f = False
            dfs2(v, path + [v])
    if f:
        paths.append(path)

cur = _path_aoki[-1]
dfs2(cur, [cur])

l = 0
for path in paths:
    if len(path) >= l:
        longest = path
        l = len(path)

path_aoki = _path_aoki[:-1] + longest

print(len(path_aoki) - 2)
