
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())


N,T,A = inpl()
T -= 1
A -= 1
lines = defaultdict(set)
for _ in range(N-1):
    a,b = inpl()
    lines[a-1].add(b-1)
    lines[b-1].add(a-1)

def dfs(s,b,d):
    global depthes
    depthes[s] = d
    for t in lines[s]:
        if t !=b:
            dfs(t,s,d+1)
    return

depthes = [-1]*N
dfs(A,-1,0)

aoki_nodes = [set() for _ in range(N)]
for i,d in enumerate(depthes):
    aoki_nodes[d].add(i)


turn = 0
nexts = set([T])
while True:
    takahashi = nexts.copy()
    nexts = set()
    for s in takahashi:
        for t in lines[s]:
            if t not in aoki_nodes[turn]:
                nexts.add(t)

    if len(nexts) == 0:
        print(turn)
        break
    elif len(aoki_nodes[turn+1] - nexts) == 0:
        print(turn+1)
        break

    turn += 1
