// Try AtCoder
// author: Leonardone

fn main() {
    let mut stdin = String::new();
    std::io::Read::read_to_string(&mut std::io::stdin(), &mut stdin).unwrap();
    let mut stdin = stdin.split_whitespace();
    let mut get = || stdin.next().unwrap();
    macro_rules! get {
        ($t:ty) => (get().parse::<$t>().unwrap());
        () => (get!(usize));
    }
    
    let n = get!();
    let u = get!() - 1;
    let v = get!() - 1;
    let mut graph = vec![vec![]; n];
    for _ in 1..n {
        let a = get!() - 1;
        let b = get!() - 1;
        graph[a].push(b);
        graph[b].push(a);
    }
    
    let mut t_dist = make_dist(&graph, u);
    
    let a_dist = make_dist(&graph, v);
    
    let mut ans = n + n;
    for i in 0..n {
        if t_dist[i].0 >= a_dist[i].0 {
            t_dist[i].0 = 0;
        }
    }
    let mut stack = vec![u];
    while let Some(x) = stack.pop() {
        if t_dist[x].0 == 0 {
            ans = std::cmp::min(ans, a_dist[x].0 - 1);
        }
        let mut cnt = 0;
        for &y in &graph[x] {
            if t_dist[y].0 > t_dist[x].0 {
                stack.push(y);
                cnt += 1;
            }
        }
        if cnt == 0 && t_dist[x].0 > 0 {
            ans = std::cmp::min(ans, a_dist[x].0 - 2);
        }
    }
    
    // println!("{:?}", a_dist);
    // println!("{:?}", t_dist);
    println!("{}", ans);
}

fn make_dist(graph: &Vec<Vec<usize>>, s: usize) -> Vec<(usize,usize)> {
    let mut dist = vec![(0, 0); graph.len()];
    dist[s] = (1, s);
    let mut stack = vec![s];
    while let Some(x) = stack.pop() {
        let c = dist[x].0 + 1;
        for &y in &graph[x] {
            if dist[y].0 == 0 {
                dist[y] = (c, x);
                stack.push(y);
            }
        }
    }
    dist
}
