N,u,v = list(map(int,input().split()))
A = [[float("inf") for i in range(N)] for i in range(N)]
for i in range(N-1):
    x,y = map(int,input().split())
    A[x-1][y-1] = 1
    A[y-1][x-1] = 1
def dijkstra(s,n,w,cost):
    d = [float("inf")] * n
    used = [False] * n
    d[s] = 0
    while True:
        v = -1
        for i in range(n):
            if (not used[i]) and (v == -1):
               v = i
            elif (not used[i]) and d[i] < d[v]:
                v = i
        if v == -1:
               break
        used[v] = True

        for j in range(n):
               d[j] = min(d[j],d[v]+cost[v][j])
    return d

Ta = dijkstra(u-1,N,N-1,A)
Ao = dijkstra(v-1,N,N-1,A)
output = 0
for i in range(N):
    if Ta[i]<Ao[i]:
        if Ao[i]-1>output:
            output = Ao[i]-1
print(output)