import sys
import queue
from collections import defaultdict

input = sys.stdin.readline
sys.setrecursionlimit(20000000)

ans = 0
n, u, v = map(int, input().split())
ab = [[] for _ in range(n)]
for i in range(n-1):
    a, b = map(int, input().split())
    ab[a-1].append(b-1)
    ab[b-1].append(a-1)

checked = [False] * n
# 深さ優先
s = u - 1
e = v - 1

def dfs(cur, l):
    if cur == e:
        return l + [cur]
    for i in ab[cur]:
        if checked[i]:
            continue
        checked[i] = True
        res = dfs(i, l + [cur])
        if res != None:
            return res
    return None

path = dfs(s, [])
checked = [False] * n
run_p = 0
if len(path) > 2:
    if len(path) % 2 == 0:
        ans = len(path) // 2 - 1
        s = path[len(path)//2 - 1]
        e = path[len(path)//2]
    else:
        ans = len(path) // 2 - 1
        s = path[len(path)//2 - 1]
        e = path[len(path)//2]
        run_p += 1
checked[e] = True


q = queue.Queue()
q.put((s, 0))
checked[s] = True
while not q.empty():
    cur, count = q.get()
    for i in ab[cur]:
        if checked[i]:
            continue
        checked[i] = True
        q.put((i, count+1))
        run_p = max(run_p, count + 1)
print(ans + run_p)