use std::collections::HashSet;
use std::io::{stdin, Read};

macro_rules! parse {
    ($iter: ident) => {
        $iter.next().unwrap().parse().unwrap()
    };
    ($iter: ident,2) => {
        (parse!($iter), parse!($iter))
    };
    ($iter: ident,3) => {
        (parse!($iter), parse!($iter), parse!($iter))
    };
    ($iter: ident,4) => {
        (parse!($iter), parse!($iter), parse!($iter), parse!($iter))
    };
    ($iter: ident, $n: ident) => {
        (&mut $iter).take($n).map(|e| e.parse().unwrap()).collect();
    };
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    let mut iter = s.split_whitespace();
    let (n, u, v): (usize, usize, usize) = parse!(iter, 3);
    let u = u - 1;
    let v = v - 1;
    let mut tree: Vec<Vec<usize>> = vec![vec![]; n];
    for _ in 0..(n - 1) {
        let (a, b): (usize, usize) = parse!(iter, 2);
        tree[a - 1].push(b - 1);
        tree[b - 1].push(a - 1);
    }
    let mut ret = 0;
    for i in 0..n {
        if tree[i].len() == 1 {
            let mut seen = HashSet::new();
            let ul = dfs(u, i, &tree, &mut seen);
            let mut seen = HashSet::new();
            let vl = dfs(v, i, &tree, &mut seen);
            // println!("{:?}", (i, ul, vl)); // DEBUG
            if vl > ul {
                ret = std::cmp::max(ret, vl - 1);
            }
        }
    }
    println!("{}", ret);
}

fn dfs(from: usize, to: usize, tree: &Vec<Vec<usize>>, seen: &mut HashSet<usize>) -> isize {
    if from == to {
        return 0;
    }
    let mut ret = 0;
    let mut m = 100000000;
    for c in &tree[from] {
        if !seen.contains(&c) {
            seen.insert(*c);
            let l = dfs(*c, to, tree, seen);
            if l >= 0 {
                return l + 1;
            }
        };
    }
    return -1;
}
