<?php


fscanf(STDIN, "%d%d%d", $n, $A, $T);

for($i=1;$i<$n;$i++){
    fscanf(STDIN, "%d%d", $t1, $t2);
    $map[$t1][$t2]=1;
    $map[$t2][$t1]=1;
}
$dmap[$T] = 0;
getDepth($T, 1);

$half = intdiv($dmap[$A] - 1, 2);
if($half != intdiv($dmap[$A], 2)){
    $add = 1;
}else{
    $add = 0;
}
$halfD = $dmap[$A] - $half;
    $start = $A;

while($dmap[$start] != $halfD){
    foreach($map[$start] as $key => $value){
        if($dmap[$key] <= $dmap[$start]){
            $start = $key;
            break;
        }
    }
}

$ans = search($start);
echo $ans -1;


function search($T){
    global $map, $dmap;
    $now = $dmap[$T];
    $return = $now;
    foreach($map[$T] as $key=> $value){
        if($dmap[$key] > $now){
            $return = max($now, search($key));
        }
    }
    return $return;
}


function getDepth($T, $depth){
    global $map, $dmap;
    foreach($map[$T] as $key => $value){
        if(!isset($dmap[$key])){
            $dmap[$key] = $depth;
            getDepth($key, $depth+1);
        }elseif($map[$key] < $depth){
            $dmap[$key] = $depth;
            getDepth($key, $depth+1);
        }
    }
}

