from scipy.sparse.csgraph import dijkstra
from scipy.sparse import csr_matrix
def main():
    n, u, v = map(int, input().split())
    graph = [[0]*n for i in range(n)]
    u -= 1
    v -= 1
    for _ in range(n-1):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        graph[a][b] = 1
        graph[b][a] = 1
    dist_t = dijkstra(csr_matrix(graph), indices=u)
    dist_a = dijkstra(csr_matrix(graph), indices=v)
    ans = 0
    for i in range(n):
        if dist_t[i] < dist_a[i]:
            buf = int(dist_t[i] + (dist_a[i] - dist_t[i])//2)
            if ans < buf:
                ans = buf
    x = 10**6
    equal_f = False
    for i in range(n):
        if dist_t[i] == dist_a[i]:
            equal_f = True
            buf = dist_t[i]
            if buf < x:
                x = buf
    if equal_f:
        if ans < x:
            ans = x
    print(ans)

if __name__ == "__main__":
    main()