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

e = [[] for i in range(N+1)]
for i in range(N-1):
    A, B = map(int, input().split())
    e[A-1].append(B-1) 
    e[B-1].append(A-1)

def dijkstra(s, d):
    d[s] = 0
    q = [s]

    while q:
        u = q.pop()
        du = d[u] + 1
        for v in e[u]:
            if du < d[v]:
                d[v] = du
                q.append(v)
du = [N+2] * N
dv = [N+2] * N
dijkstra(u-1, du)
dijkstra(v-1, dv)
#print("T", du)
#print("A", dv)

e = 0
for i in range(N):
    if du[i] <= dv[i]:
        e = max(e, du[i])
e0 = N+1
for i in range(N):
    if du[i] == dv[i]:
        e0 = min(e0, du[i])
e = min(e, e0)
#print("e=",e, "T-A=%d"%du[v-1])
print(e)


