N,u,v = map(int,input().split())
inf = 10**9
d = [[inf for i in range(N+1)] 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)
    d[a][b] = 1
    d[b][a] = 1
def warshall_floyd(d):
    #d[i][j]: iからjへの最短距離
    for k in range(1,n+1):
        for i in range(1,n+1):
            for j in range(1,n+1):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d
warshall_floyd(d)
n = d[u][v]

a = n//2
if n % 2 == 0:
    for i in range(N):
        if (d[u][i] == a) & (d[v][i] == a)
            s = i
            break
for j in G[s]:
    if d[u][j] == a-1:
        u = j
    if d[v][j] == a-1:
        v = j
if n % 2 == 0:
    G[u].remove(s)
else:
    G[u].remove(v)
ans = (n-1)//2

F = [u]
list = []
while len(F) > 0:
    x = F.pop(0)
    list.append(x)
    for j in G[x]:
        if j not in F:
            if j not in list:
                F.append(j)
m = 0
for i in list:
    m = max(m,i)
ans += m + ((n-1)%2)
print(ans)