#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline
INF = 10**9

class RMQ:
    def __init__(self, a):
        self.n = len(a)
        self.size = 2**(self.n - 1).bit_length()
        self.data = [(INF, INF) for _ in range(2*self.size-1)]
        self.initialize(a)

    # Initialize data
    def initialize(self, a):
        for i in range(self.n):
            self.data[self.size + i - 1] = a[i][:]
        for i in range(self.size-2, -1, -1):
            self.data[i] = min(self.data[i*2 + 1], self.data[i*2 + 2])[:]

    # Update ak as x
    def update(self, k, x):
        k += self.size - 1
        self.data[k] = x
        while k > 0:
            k = (e - 1) // 2
            self.data[k] = min(self.data[2*k+1], self.data[2*k+2])[:]

    # Min value in [l, r)
    def query(self, l, r):
        L = l + self.size; R = r + self.size
        s = (INF, INF)
        while L < R:
            if R & 1:
                R -= 1
                s = min(s, self.data[R-1])[:]
            if L & 1:
                s = min(s, self.data[L-1])[:]
                L += 1
            L >>= 1; R >>= 1
        return s

class LCA:
    def __init__(self, edge, root):
        self.edge = edge[:]
        self.path = []
        self.depth = []
        self.index = [0] * n
        self.euler_tour(-1, root, 0, 0)
        dat = list(zip(self.depth, self.path))
        self.rmq = RMQ(dat)

    # Lowest ancestor of u, v
    def get_lca(self, u, v):
        l, r = self.index[u], self.index[v]
        if l > r:
            l, r = r, l
        return self.rmq.query(l, r+1)[1]

    def get_depth(self, v):
        return self.depth[self.index[v]]

    def euler_tour(self, prev, v, d, k):
        self.index[v] = k
        self.path.append(v)
        self.depth.append(d)
        k += 1
        for item in self.edge[v]:
            if prev == item:
                continue
            k = self.euler_tour(v, item, d + 1, k)
            self.path.append(v)
            self.depth.append(d)
            k += 1
        return k

n, u, v = [int(item) for item in input().split()]
u -= 1; v -= 1
edge = [[] for _ in range(n)]

for i in range(n-1):
    a, b = [int(item) for item in input().split()]
    a -= 1; b -= 1
    edge[a].append(b)
    edge[b].append(a)

lca = LCA(edge, v)
frm = lca.get_depth(v)
too = lca.get_depth(u)
up = (too - frm - 1) // 2
max_depth = too 

def dfs(p, v, lim):
    global max_depth
    max_depth = max(max_depth, lca.get_depth(v))
    for nv in edge[v]:
        if nv == p:
            continue
        if lca.get_depth(v) < lim:
            continue
        dfs(v, nv, lim)
if too == 1 and max_depth == 1:
    print(0)
    exit()
if too == 2 and max_depth == 2:
    print(1)
    exit()

dfs(-1, u, too - up)
ans = 0
if (too - frm) % 2 == 1:
    ans = up + max_depth - (too - up)
else:
    ans = up + max_depth - (too - up) - 1
print(ans)