import sys
import math
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res
def gcd(x, y):
    if x < y: x, y = y, x
    div = x % y
    while div != 0:
        x, y = y, div
        div = x % y
    return y

N,u,v=LI()

TR=[[] for i in range(N+1)]
for _ in range(N-1):
    i,j=LI()
    TR[i].append(j)
    TR[j].append(i)

DIST=[(-1,-1) for i in range(N+1)]
DIST[v] = (0, -1)
def dfs(root=v):
    maxdist = DIST[root][0]
    for vtx in TR[root]:
        if DIST[vtx][0] == -1:
            DIST[vtx] = (DIST[root][0] + 1, -1)
            maxdist = max(maxdist, dfs(vtx))
    DIST[root] = (DIST[root][0], maxdist)
    return maxdist

DIST2=[(-1,-1) for i in range(N+1)]
LST = 0
def dfs2(root=u):
    global LST
    maxdist = DIST2[root][0]
    for vtx in TR[root]:
        if DIST2[vtx][0] == -1 and DIST2[root][0] + 1 < DIST[vtx][0]:
            LST = max(LST, DIST[vtx][0])
            DIST2[vtx] = (DIST2[root][0] + 1, -1)
            maxdist = max(maxdist, dfs2(vtx))
    DIST2[root] = (DIST2[root][0], maxdist)
    return maxdist

dfs()
dfs2()
# print(DIST)
# print(DIST2)

print(max(0, LST-1))
