import sys

input = sys.stdin.readline





import heapq

def dijkstra(s, E):

    inf = float("inf")

    d = [inf for i in range(len(E))]

    d[s] = 0

    q = [(0, s)]

    while q:

        c, p = heapq.heappop(q)

        if d[p] < c:

            continue

        for cost, to in E[p]:

            if d[to] > d[p] + cost:

                d[to] = d[p] + cost

                heapq.heappush(q, (d[to], to))

    return d





def main():

    N, u, v = list(map(int, input().split()))

    E = [[] for i in range(N)]

    for _ in range(N-1):

        a, b = list(map(int, input().split()))

        E[a-1].append((1, b-1))

        E[b-1].append((1, a-1))

    du = dijkstra(u-1, E)

    dv = dijkstra(v-1, E)

    ans = 0

    for i, j in zip(du, dv):

        if i < j:

            ans = max(ans, j)

    print((ans - 1))





if __name__ == '__main__':

    main()

import sys

input = sys.stdin.readline





def treeDist(u, E):

    D = [-1]*len(E)

    q = [(u, 0)]

    while q:

        i, d = q.pop()

        if D[i] != -1:

            continue

        D[i] = d

        for j in E[i]:

            q.append((j, d+1))

    return D





def main():

    N, u, v = list(map(int, input().split()))

    E = [[] for i in range(N)]

    for _ in range(N-1):

        a, b = list(map(int, input().split()))

        E[a-1].append(b-1)

        E[b-1].append(a-1)



    D1 = treeDist(u-1, E)

    D2 = treeDist(v-1, E)

    ans = 0

    for d1, d2 in zip(D1, D2):

        if d1 < d2:

            ans = max(ans, d2)

    print((ans-1))





if __name__ == '__main__':

    main()

import sys

input = sys.stdin.readline
import heapq


def dijkstra(s, E):
    inf = float("inf")
    d = [inf for i in range(len(E))]
    d[s] = 0
    q = [(0, s)]
    while q:
        c, p = heapq.heappop(q)
        if d[p] < c:
            continue
        for cost, to in E[p]:
            if d[to] > d[p] + cost:
                d[to] = d[p] + cost
                heapq.heappush(q, (d[to], to))
    return d


def main():
    N, u, v = list(map(int, input().split()))
    E = [[] for i in range(N)]
    for _ in range(N - 1):
        a, b = list(map(int, input().split()))
        E[a - 1].append((1, b - 1))
        E[b - 1].append((1, a - 1))
    du = dijkstra(u - 1, E)
    dv = dijkstra(v - 1, E)
    ans = 0
    for i, j in zip(du, dv):
        if i < j:
            ans = max(ans, j)
    print((ans - 1))


if __name__ == "__main__":
    main()

import sys

input = sys.stdin.readline


def treeDist(u, E):
    D = [-1] * len(E)
    q = [(u, 0)]
    while q:
        i, d = q.pop()
        if D[i] != -1:
            continue
        D[i] = d
        for j in E[i]:
            q.append((j, d + 1))
    return D


def main():
    N, u, v = list(map(int, input().split()))
    E = [[] for i in range(N)]
    for _ in range(N - 1):
        a, b = list(map(int, input().split()))
        E[a - 1].append(b - 1)
        E[b - 1].append(a - 1)
    D1 = treeDist(u - 1, E)
    D2 = treeDist(v - 1, E)
    ans = 0
    for d1, d2 in zip(D1, D2):
        if d1 < d2:
            ans = max(ans, d2)
    print((ans - 1))


if __name__ == "__main__":
    main()

-import heapq -def dijkstra(s, E): -    inf = float("inf") -    d = [inf for i in range(len(E))] -    d[s] = 0 -    q = [(0, s)] +def treeDist(u, E): +    D = [-1] * len(E) +    q = [(u, 0)] -        c, p = heapq.heappop(q) -        if d[p] < c: +        i, d = q.pop() +        if D[i] != -1: -        for cost, to in E[p]: -            if d[to] > d[p] + cost: -                d[to] = d[p] + cost -                heapq.heappush(q, (d[to], to)) -    return d +        D[i] = d +        for j in E[i]: +            q.append((j, d + 1)) +    return D -        E[a - 1].append((1, b - 1)) -        E[b - 1].append((1, a - 1)) -    du = dijkstra(u - 1, E) -    dv = dijkstra(v - 1, E) +        E[a - 1].append(b - 1) +        E[b - 1].append(a - 1) +    D1 = treeDist(u - 1, E) +    D2 = treeDist(v - 1, E) -    for i, j in zip(du, dv): -        if i < j: -            ans = max(ans, j) +    for d1, d2 in zip(D1, D2): +        if d1 < d2: +            ans = max(ans, d2)