import heapq;

n, u, v = [int(v) for v in input().split()]

vert = []

for i in range(n):
    vert.append([])

for i in range(n - 1):
    a, b = [int(v) - 1 for v in input().split()]
    vert[a].append(b)
    vert[b].append(a)

taka = u-1
aoki = v-1

q = []
heapq.heappush(q, (0, aoki))
aoki_dist = [-1] * n
closed = 0

while len(q) > 0:
    c0, i = heapq.heappop(q)
    aoki_dist[i] = c0
    closed |= (1 << i)

    c = c0 + 1
    for l in vert[i]:
        if closed & (1 << l) != 0:
            continue
        heapq.heappush(q, (c, l))

closed = 0
heapq.heappush(q, (0, taka))
max_dist = aoki_dist[taka] - 1

while len(q) > 0:
    c0, i = heapq.heappop(q)
    closed |= (1 << i)

    c = c0 + 1
    for l in vert[i]:
        if closed & (1 << l) != 0:
            continue
        closed |= (1 << l)
        if c >= aoki_dist[l]:
            continue
        if max_dist < aoki_dist[l] - 1:
            max_dist = aoki_dist[l] - 1
        heapq.heappush(q, (c, l))

print(max_dist)