
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 = [[] for _ in range(N)]
for _ in range(N-1):
    a,b = inpl()
    lines[a-1].append(b-1)
    lines[b-1].append(a-1)

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

stack = [(A,-1,0)]
aoki_nodes = [set() for _ in range(N)]

while len(stack)>0:
    s,b,d = stack.pop()
    aoki_nodes[d].add(s)
    for t in lines[s]:
        if t != b and d < N:
            stack.append((t,s,d+1))

turn = 0
takahashi = [set() for _ in range(N)]
takahashi[0].add(T)
while True:
    nexts = set()
    for s in takahashi[turn]:
        if s in aoki_nodes[turn]:
            continue
        for t in lines[s]:
            if t not in aoki_nodes[turn]:
                takahashi[turn+1].add(t)
    if len(takahashi[turn+1]) == 0:
        print(turn)
        break
    turn += 1
    assert turn<N+5, "error"
