import itertools, heapq, bisect
from collections import defaultdict as ddic, deque, Counter

rr = raw_input
rri = lambda: int(raw_input())
rrm = lambda: map(int, raw_input().split())
MOD = 10 ** 9 + 7

###

def solve(N, T, A, graph):
    if T == A: return 0
    stack = [(A, None)]
    seen = {A}
    back = {}
    while stack:
        node, par = stack.pop()
        back[node] = par
        for nei in graph[node]:
            if nei != par:
                if nei not in seen:
                    stack.append((nei, node))
                    seen.add(nei)

    path = [T]
    while back[path[-1]] is not None:
        path.append(back[path[-1]])

    def bfs(source, par):
        queue = deque([(source, par, 0)])
        d=  0
        while queue:
            node, par, d = queue.popleft()
            for nei in graph[node]:
                if nei != par:
                    queue.append((nei, node, d+1))
        return d
    
    ans = 0
    i = 0
    j = len(path) - 1
    while i + 2 < j:
        i += 1
        j -= 1
        ans += 1
    # now T goes away from A
    #print "!", path[i], path[i+1], ans
    ans += j-i-1
    ans += bfs(path[i], path[i+1])
    return ans


N, T, A = rrm()
T -= 1; A -= 1
graph = [[] for _ in xrange(N)]

for _ in xrange(N-1):
    a, b = rrm()
    a -= 1; b -= 1
    graph[a].append(b)
    graph[b].append(a)

print solve(N, T, A, graph)
