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(1,N+1):
    d[i][i] = 0
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)

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)
ans = 0
for i in HA:
    x = d[u][i]
    y = d[v][i]
    if y > x:
        a = x + (y-x)//2
        ans = max(a,ans)
print(ans)