import sys
sys.setrecursionlimit(10000000)
# input = sys.stdin.readline
# from bisect import *
# from collections import *
# from heapq import *
# import functools
# import itertools
# import math
INF = 500000
MOD = 10**9+7

def dfs(x, d):
    dep[x] = d
    for y in es[x]:
        if dep[y] == None:
            dfs(y, d+1)

def find(x):
    if dep[u] <= dep[x] and x != u:
        return -1
    if x == u:
        return x
    for y in es[x]:
        if dep[x] < dep[y]:
            tmp = find(y)
            if tmp != -1:
                tmp = x if dep[x] == l else tmp
                return tmp

def Maxd(x):
    ret = dep[x]
    for y in es[x]:
        if dep[x] < dep[y]:
            ret = max(ret, Maxd(y))
    return ret

N, u, v = map(int, input().split())
u -= 1
v -= 1
es = [[] for i in range(N)]
for i in range(N-1):
    a, b = map(lambda x: int(x)-1, input().split())
    es[a].append(b)
    es[b].append(a)
dep = [None] * N
dfs(v, 0)
l = u//2+1
k = find(v)
print(dep[u]-l+Maxd(k)-l+(dep[u]==2))
