import sys
sys.setrecursionlimit(1000000)
N, u, v = map(int, input().split())
u -= 1
v -= 1

G = [[] for _ in range(N)]
elens = [0] * N

for _ in range(N - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    G[a].append(b)
    G[b].append(a)
    elens[a] += 1
    elens[b] += 1


TAKAHASHI = [0] * N

def dfs_takahashi(cur: int, past: int, G, d: int):
    TAKAHASHI[cur] = d

    for nx in G[cur]:
        if nx == past:
            continue
        dfs_takahashi(nx, cur, G, d + 1)

def dfs_aoki(cur: int, past: int, G, d: int):

    if elens[cur] == 1 and G[cur][0] == past:
        return d - 1, cur == u

    ret = 0
    ret_te = cur == u

    for nx in G[cur]:
        if nx == past:
            continue

        depth, takahashi_exists = dfs_aoki(nx, cur, G, d + 1)
        if takahashi_exists and d <= TAKAHASHI[cur]:
            return depth, True

        ret = max(ret, depth)
        ret_te |= takahashi_exists

    return ret, ret_te

dfs_takahashi(u, -1, G, 0)
d, _ = dfs_aoki(v, -1, G, 0)
print(d)