use std::collections::{HashSet, VecDeque};

#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        u: usize,
        v: usize,
        ab: [(usize, usize); n - 1]
    }
    let mut adjacency = vec![vec![]; n + 1];
    for (ai, bi) in ab {
        adjacency[ai].push(bi);
        adjacency[bi].push(ai);
    }

    let mut height = vec![0; n + 1];
    let mut parent = vec![0; n + 1];
    let mut queue = VecDeque::new();
    let mut visited = HashSet::new();
    queue.push_back(v);
    while queue.len() > 0 {
        let w = queue.pop_front().unwrap();
        visited.insert(w);
        for &x in adjacency[w].iter() {
            if !visited.contains(&x) {
                height[x] = height[w] + 1;
                parent[x] = w;
                queue.push_back(x);
            }
        }
    }
    // println!("{:?}", height);
    // println!("{:?}", parent);

    let mut u_ancestor = vec![u];
    let mut w = u;
    while parent[w] != v {
        u_ancestor.push(parent[w]);
        w = parent[w];
    }
    // println!("{:?}", u_ancestor);

    let mut result = height[u] / 2;
    let mut z = u;
    let h = (height[u] - 1) / 2;
    for &w in u_ancestor[0..h].iter() {
        let mut max = 0;
        let mut max_node = 0;
        let mut queue = VecDeque::new();
        let mut visited = HashSet::new();
        queue.push_back(w);
        while queue.len() > 0 {
            let x = queue.pop_front().unwrap();
            visited.insert(x);
            for &y in adjacency[x].iter() {
                if !visited.contains(&y) && !u_ancestor.contains(&y) && height[y] > height[w] {
                    let d = height[y] - height[w];
                    if d > max {
                        max = d;
                        max_node = y;
                    }
                    queue.push_back(y);
                }
            }
        }
        // println!("{}", max);
        let d = max + height[u] - height[w];
        if d > result {
            result = d;
            z = max_node;
        }
        // println!("{} {}", w, d);
    }
    // println!("{} {}", result, z);

    println!("{}", result + (height[z] - result - 1));
}
