import sys
sys.setrecursionlimit(1000000)

N, u, v = map(int, input().split())

u -= 1
v -= 1

graph = [[] for i in range(N)]
for i in range(N - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    graph[a].append(b)
    graph[b].append(a)

def calcDist(cur, par, dst, lst):
    lst[cur] = dst
    for neighbour in graph[cur]:
        if neighbour == par: continue
        calcDist(neighbour, cur, dst + 1, lst)
        
uDist = [[] for i in range(N)]
vDist = [[] for i in range(N)]
calcDist(u, -1, 0, uDist)
calcDist(v, -1, 0, vDist)

best = 0
for node in range(N):
    if uDist[node] <= vDist[node]:
        if any(vDist[n] > vDist[node] for n in graph[node]) or (vDist[node]%2!=uDist[node]%2):
            best = max(best, uDist[node])
        else:
            best = max(best, uDist[node] - 1)
print(best)
