import heapq
WHITE = 0
GRAY = 1
BLACK = 2
INFTY = 10**16
def dijkstra(s, VC):
    color = [WHITE for i in range(N)]
    d = [INFTY for i in range(N)]
    d[s] = 0
    pq = []
    heapq.heappush(pq, (0, s))

    while len(pq) != 0:
        u = heapq.heappop(pq)[1]
        color[u] = BLACK

        for v, c in VC[u]:
            if color[v] != BLACK:
                if d[u] + c < d[v]:
                    d[v] = d[u] + c
                    color[v] = GRAY
                    heapq.heappush(pq, (d[v], v))

    return d

N, T, A = map(int, input().split())
V = [[] for i in range(N)]
# VB = [[] for i in range(N)]
for i in range(N-1):
    u, v = list(map(int, input().split()))
    V[u-1].append([v-1, 1])
    V[v-1].append([u-1, 1])

dt = dijkstra(T-1, V)
da = dijkstra(A-1, V)
# tmp = 10**16
# base = 10 ** 15
# ans = [0 for i in range(N)]
max_a = -1
max_i = -1
for i, a in enumerate(da):
    if max_a < a:
        max_a = a
        max_i = i
    elif max_a == a and i == T-1:
        max_i = i
t = dt[max_i]
a = max_a - t
ans = a - int(t == 0)
print(ans)
# print(t, a)