use std::io;
use std::cmp;
use std::collections::BinaryHeap;
use std::collections::HashMap;
use std::collections::HashSet;
use std::f64::consts::PI;

fn read_line() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();
    buf
}

fn dfs(v: usize, g: &Vec<Vec<usize>>, memo: &mut Vec<i32>, s: i32) {
    if memo[v] >= 0 {
        return;
    }
    memo[v] = s;
    for t in g[v].iter() {
        dfs(*t, g, memo, s+1);
    }
}

fn dfs2(v: usize, g: &Vec<Vec<usize>>, memo: &Vec<i32>, visited: &mut Vec<bool>, s: i32) -> i32 {
    if memo[v] <= s {
        return memo[v];
    } else if visited[v] {
        return memo[v] - 1;
    }
    visited[v] = true;
    let mut res = s;
    for t in g[v].iter() {
        res = cmp::max(res, dfs2(*t, g, memo, visited, s+1));
    }
    res
}

fn main() {
    let line: Vec<usize> = read_line().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let n = line[0];
    let u = line[1] - 1;
    let v = line[2] - 1;

    let mut g = vec![Vec::new(); n];
    for i in 0..n-1 {
        let line: Vec<usize> = read_line().split_whitespace().map(|s| s.parse().unwrap()).collect();
        let a = line[0] - 1;
        let b = line[1] - 1;
        g[a].push(b);
        g[b].push(a);
    }    
    let mut memo = vec![-1; n];
    dfs(v, &g, &mut memo, 0);
    let mut visited = vec![false; n];
    let ans = dfs2(u, &g, &memo, &mut visited, 0);
    println!("{}", ans);
}
