import collections
def main():

    N, u, v = map(int, input().split())
    graph = collections.defaultdict(list)
    for _ in range(N-1):
        a, b = map(int, input().split())
        graph[a].append(b)
        graph[b].append(a)

    if N == 2: return 0

    cur = []
    visited = set()
    dist0 = [0 for _ in range(N)]
    for a in range(1, N+1):
        if len(graph[a]) == 1:
            cur.append(a)
            visited.add(a)

    l = 0
    while cur:
        temp = []
        l += 1
        for a in cur:
            for b in graph[a]:
                if b != v and b not in visited:
                    dist0[b-1] = l
                    temp.append(b)
                    visited.add(b)
        cur = temp

    dist1 = [0 for _ in range(N)]
    cur = [v]
    visited = set()
    l = 0
    while cur:
        l += 1
        temp = []
        for a in cur:
            for b in graph[a]:
                if b not in visited:
                    temp.append(b)
                    visited.add(b)
                    dist1[b-1] = l
        cur = temp

    dist2 = [0 for _ in range(N)]
    cur = [u]
    visited = set()
    l = 0
    while cur:
        l += 1
        temp = []
        for a in cur:
            for b in graph[a]:
                if b not in visited:
                    temp.append(b)
                    visited.add(b)
                    dist2[b-1] = l
        cur = temp

    # print(dist0)
    # print(dist1)
    # print(dist2)

    ans = -1
    for i in range(N):
        if dist1[i] < dist2[i]:
            d = dist1[i] + dist2[i]
            if d % 2 == 0:
                d -= 1
            ans = min(ans, d)
        else:
            d = dist2[i] + dist0[i]
            if d % 2 == 0:
                d -= 1
            ans = max(ans, d)
    return ans


if __name__ == '__main__':
    print(main())