<?php
list($n, $b, $a) = ints();
for($i = 0; $i < $n - 1; $i++){
    list($f, $t) = ints();
    $map[$f][] = $t;
    $map[$t][] = $f;
}
for($i = 1; $i <= $n; $i++){
    $d[$i] = 10**10;
    $dd[$i] = 10**10;
    $e[$i] = 0;
}
$d[-1] = -1;
$dd[-1] = -1;
$dist = 0;
$max = 0;
dfs(-1, $a, false);
dfs2(-1, $b, false);
//o($max);
//Aが移動した距離
//o($dist);
//o($dd);
//o($d);
$m = 0;
for($i = 1; $i <= $n; $i++){
  if($dd[$i] < $d[$i]){
      $m = max($m, $d[$i]) - (10**10+$dd[$i]-$d[$i])%2;
  }  
}
echo $m;
//$distA = $max - ($max - $dist) % 2;
//echo $distA;
//if(($max - $dist) % 2 == 1){
//    if(($max-$dist % 2) == 1)$distA++;
//}
function dfs($from, $current, $done){
    global $map, $d, $b, $e, $dist, $max;
    $d[$current] = $d[$from] + 1;
    $e[$current] = $done;
    if($done){
        $max = max($max, $d[$current]);
    }
    foreach($map[$current] as $to){
        if($to != $from){
            if($to == $b){
                $done = true;
                $dist = $d[$current];
            }
            dfs($current, $to, $done);
        }
    }
}
function dfs2($from, $current){
    global $map, $dd;
    $dd[$current] = $dd[$from] + 1;
    foreach($map[$current] as $to){
        if($to != $from){
            dfs2($current, $to);
        }
        
    }
}

//o($dist);
//print_r($d);
//print_r($e);

function str(){
  return trim(fgets(STDIN));
}
function ints(){
  return array_map("intval", explode(" ", trim(fgets(STDIN))));
}
function int(){
  return intval(trim(fgets(STDIN)));
}
function o(...$val){
    if(count($val)==1)$val = array_shift($val);
    $trace = debug_backtrace();
    echo $trace[0]['line'].")";
    if(is_array($val)){
        if(count($val) == 0){
            echo "empty array";
        }elseif(!is_array(current($val))){
            echo "array:";
            echo implode(" ", $val)."\n";
        }else{
            echo "array:array\n";
            foreach($val as $row){
                echo implode(" ", $row)."\n";
            }
        }
    }else{
        echo $val."\n";
    }
}