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


if (len(T[u])) == 1 and (T[u][0][0] == v):
    print(0)
    exit()


def dijkstra(graph, start, inf=float('inf')):
    import heapq
    n = len(graph)
    distances = [inf] * n
    distances[start] = 0
    visited = [False] * n

    # 距離・頂点
    hq = [(0, start)]
    while hq:
        dist, fr = heapq.heappop(hq)
        visited[fr] = True

        for to, cost in graph[fr]:
            new_dist = distances[fr] + cost
            if (visited[to]) or (distances[to] <= new_dist):
                continue

            distances[to] = new_dist
            heapq.heappush(hq, (new_dist, to))

    return distances


U_dist = dijkstra(T, u)
V_dist = dijkstra(T, v)

Good = set()
for i, ud, vd in zip(range(N), U_dist, V_dist):
    if ud < vd:
        Good.add(i)


T2 = [[] for i in range(N)]
for a, b, d in E:
    if (a in Good) and (b in Good):
        T2[a].append([b, 1])
        T2[b].append([a, 1])

longest = -1
tmp_max = 0
for n, d in enumerate(dijkstra(T2, u)):
    if d != float('inf'):
        if tmp_max < d:
            tmp_max = d
            longest = n

if longest == -1:
    print(1)
    exit()

reach = V_dist[longest]
if abs(tmp_max - reach) % 2 == 1:
    print(tmp_max)
else:
    print(tmp_max - 1)
