use std::cmp::*;
use std::io::*;

fn dfs(v: usize, p: usize, d: &mut Vec<usize>, g: &Vec<Vec<usize>>) {
    for &nv in g[v].iter() {
        if nv != p {
            d[nv] = d[v] + 1;
            dfs(nv, v, d, &g);
        }
    }
}

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let u: usize = itr.next().unwrap().parse::<usize>().unwrap() - 1;
    let v: usize = itr.next().unwrap().parse::<usize>().unwrap() - 1;
    if n == 2 {
        println!("0");
        return;
    }

    let mut g = vec![Vec::new(); n];
    for _ in 0..n - 1 {
        let a: usize = itr.next().unwrap().parse::<usize>().unwrap() - 1;
        let b: usize = itr.next().unwrap().parse::<usize>().unwrap() - 1;
        g[a].push(b);
        g[b].push(a);
    }

    let mut t = vec![0; n];
    let mut a = vec![0; n];
    dfs(u, u, &mut t, &g);
    dfs(v, v, &mut a, &g);

    // t
    let mut td = 0;
    let mut ti = 0;
    for i in 0..n {
        if a[i] > t[i] && t[i] > td {
            td = t[i];
            ti = i;
        }
    }
    if td == 0 {
        println!("1");
    } else {
        println!("{}", a[ti] - 1);
    }
}
