N,u,v = map(int,input().split())
inf = 10**9
edge = [[] for j in range(N+1)]
G = [[] for i in range(N+1)]
for i in range(N-1):
    a,b = map(int,input().split())
    G[a].append(b)
    G[b].append(a)
    edge[a].append([1,b])
    edge[b].append([1,a])
import heapq
def dis(s):
    #始点sから各頂点への最短距離
    d = [float("inf")] * (N+1)
    used = [True] * (N+1) #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for e in edge[s]:
        heapq.heappush(edgelist,e)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge[1]]:
            continue
        v = minedge[1]
        d[v] = minedge[0]
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,[e[0]+d[v],e[1]])
    return d
U = dis(u)
V = dis(v)
F = [v]
list = []
HA = []
while len(F) > 0:
    x = F.pop(0)
    list.append(x)
    h = []
    for j in G[x]:
        if j not in F:
            if j not in list:
                F.append(j)
                h.append(j)
    if len(h) == 0:
        HA.append(x)
m = -1
for i in HA:
    x = U[i]
    y = V[i]
    if y > x:
        if y > m:
            s = i
x = U[s]
y = V[s]
ans = x + (y-x)//2
print(ans)