unittest
{
	assert( [ "5 4 1", "1 2", "2 3", "3 4", "3 5" ].solve == 2 );
	assert( [ "5 4 5", "1 2", "1 3", "1 4", "1 5" ].solve == 1 );
	assert( [ "2 1 2", "1 2" ].solve == 0 );
	assert( [ "9 6 1", "1 2", "2 3", "3 4", "4 5", "5 6", "4 7", "7 8", "8 9" ].solve == 5 );
}



import std.algorithm;
import std.container;
import std.conv;
import std.format;
import std.range;
import std.stdio;

void main()
{
	stdin.byLineCopy.solve.writeln;
}

auto solve( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = 0L;
	auto u = 0L;
	auto v = 0L;
	input.front.formattedRead!"%s %s %s"( n, u, v );
	u--;
	v--;
	auto abs = new long[ 2 ][ n - 1 ];
	foreach( ref ab; abs )
	{
		input.popFront;
		ab = input.front.split.to!( long[] );
		ab[] -= 1;
	}
	
	// 移動範囲を探索
	auto nss = toAdjacencyList!true( n, abs );
	auto as = bfs( nss, v );
	auto ts = bfsEx( nss, as, u );
	
	// 端に追い詰められるパターンのターン数を計算
	auto ans = 0L;
	foreach( i, t, a; lockstep( ts, as ) )
	{
		if( nss[ i ].length == 1 && t <= a ) ans = max( ans, a - 1 );
	}
	return ans;
}

// 辺配列から隣接リストを作成
auto toAdjacencyList( bool undirected = false )( long n, long[ 2 ][] es )
{
	auto nss = new long[][ n ];
	foreach( e; es )
	{
		nss[ e[ 0 ] ] ~= e[ 1 ];
		static if( undirected ) nss[ e[ 1 ] ] ~= e[ 0 ];
	}
	return nss;
}

// グラフの始点指定最短経路探索（幅優先探索）
auto bfs( long[][] nss, long s )
{
	auto ds = new long[ nss.length ];
	ds[] = long.max;
	ds[ s ] = 0;
	
	auto queue = make!DList( s );
	while( !queue.empty )
	{
		auto f = queue.front;
		queue.removeFront();
		
		foreach( t; nss[ f ] )
		{
			if( ds[ t ] < long.max ) continue;
			
			ds[ t ] = ds[ f ] + 1;
			queue.insertBack( t );
		}
	}
	return ds;
}

// グラフの始点指定最短経路探索（幅優先探索）
auto bfsEx( long[][] nss, long[] as, long s )
{
	auto ds = new long[ nss.length ];
	ds[] = long.max;
	ds[ s ] = 0;
	
	auto queue = make!DList( s );
	while( !queue.empty )
	{
		auto f = queue.front;
		queue.removeFront();
		
		foreach( t; nss[ f ] )
		{
			if( ds[ t ] < long.max || as[ t ] <= ds[ f ] ) continue;		// 青木君とすれ違うことはできない
			
			ds[ t ] = ds[ f ] + 1;
			queue.insertBack( t );
		}
	}
	return ds;
}
