import sys
from collections import deque

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, T, A = map(int, input().split())
    edge = [[] for _ in range(n)]
    for _ in range(n - 1):
        a, b = map(int, input().split())
        edge[a - 1].append(b - 1)
        edge[b - 1].append(a - 1)

    dist = [f_inf] * n
    dist[A - 1] = 0
    que = deque([A - 1])
    while que:
        v = que.popleft()
        for u in edge[v]:
            if dist[u] == f_inf:
                dist[u] = dist[v] + 1
                que.append(u)

    half_dist = dist[T - 1] // 2
    visited_A = [False] * n
    visited_A[A - 1] = True
    que = deque([A - 1])
    while que:
        v = que.popleft()
        for u in edge[v]:
            if dist[u] <= half_dist and not visited_A[u]:
                visited_A[u] = True
                que.append(u)

    dist2 = [f_inf] * n
    dist2[T - 1] = 0
    que = deque([T - 1])
    while que:
        v = que.popleft()
        for u in edge[v]:
            if dist2[u] == f_inf and not visited_A[u]:
                dist2[u] = dist2[v] + 1
                que.append(u)

    target = -1
    max_dist = -1
    for i in range(n):
        if dist2[i] != f_inf:
            if max_dist < dist2[i]:
                max_dist = dist2[i]
                target = i

    res = dist[target] - 1
    print(res)


if __name__ == '__main__':
    resolve()
