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

    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

    ans = -1
    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:
                    if l >= dist1[b-1]:
                        d = l + dist1[b-1]-1
                        if d % 2 == 0: d -= 1
                        ans = max(ans, d)
                    else:
                        if l % 2 == 0:
                            ans = max(ans, l-1)
                        else:
                            ans = max(ans, l)
                        temp.append(b)
                        visited.add(b)
                        dist2[b-1] = l
        cur = temp
        # if len(cur) > 0: ans = max(ans, l)

    return ans


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