# -*- coding: utf-8 -*-

def get_input(inp):
    li = inp.split("\n")

    def inner():
        return li.pop(0)
    return inner

"""
from sys import setrecursionlimit
setrecursionlimit(100000)

from collections import Counter, deque
from heapq import heappush, heappop
from bisect import # docs.python.jp/3/library/bise…
from itertools import product, combinations

"""
##################################################
from tqdm import tqdm
from string import ascii_lowercase
INPUT = """9 6 1
1 2
2 3
3 4
4 5
5 6
4 7
7 8
8 9
"""
# 1:11:39
input = get_input(INPUT)

# -*- coding: utf-8 -*-


# -*- coding: utf-8 -*-
from heapq import heapify, heappop, heappush
from collections import defaultdict, deque
import sys
#input = sys.stdin.readline
def inpl(): return list(map(int, input().split()))

class LCA:
    # ダブリングver
    def __init__(self, G):
        self.N = len(G)
        self.base = int.bit_length(self.N)
        self.depth = [-1]*self.N
        self.parents = [[-1]*self.base for _ in range(self.N)]
        self.parents[0][0] = 0
        Q = [0]
        self.depth[0] = 0

        while Q:
            p = Q.pop()
            for q in G[p]:
                if self.depth[q] != -1:
                    continue
                self.parents[q][0] = p
                self.depth[q] = self.depth[p] + 1
                Q.append(q)

        for i in range(1, self.base):
            for j in range(self.N):
                self.parents[j][i] = self.parents[self.parents[j][i-1]][i-1]


    def find_ancestor(self, a, b):
        if self.depth[a] > self.depth[b]:
            a, b = b, a
        d = self.depth[b] - self.depth[a]
        f = 2**(self.base-1)
        c = b*1
        while f:
            if d&f:
                c = self.parents[c][int.bit_length(f)-1]
            f //= 2
        if c == a:
            return c, 1
        f = 2**(self.base-1)
        while f:
            na = self.parents[a][int.bit_length(f)-1]
            nc = self.parents[c][int.bit_length(f)-1]
            if na != nc:
                a = na*1
                c = nc*1
            f //= 2
        return self.parents[a][0], 0

    def distance(self, a, b):
        c, _ = self.find_ancestor(a, b)
        return self.depth[a] + self.depth[b] - 2*self.depth[c]

N, u, v = inpl()
u -= 1
v -= 1
G = [[] for _ in range(N)]
for i in range(N-1):
    a, b = inpl()
    G[a-1].append(b-1)
    G[b-1].append(a-1)

lca = LCA(G)

isleaf = [1]*N

Q = deque()
Q.append(0)
searched = [0]*N
searched[0] = 1
while Q:
    p = Q.popleft()
    for q in G[p]:
        if searched[q]:
            continue
        isleaf[p] = 0
        searched[q] = 1
        Q.append(q)

ans = 0
for i in range(N):
    if len(G[i]) > 1:
        continue
    uc = lca.find_ancestor(u, i)[0]
    vc = lca.find_ancestor(v, i)[0]
    
    if lca.depth[uc] >= lca.depth[vc]:
        ans = max(ans, lca.depth[v] + lca.depth[i] - 2*lca.depth[vc] - 1)
    else:
        if lca.distance(u, vc) < abs(lca.depth[v] - lca.depth[vc]) - 1:
            ans = max(ans, lca.depth[v] + lca.depth[i] - 2*lca.depth[vc] - 1)
print(ans)