#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,n) for(int i = 0;i < (int)(n);i++)
#define RREP(i,n) for(int i = (int)n-1;i >= 0;i--)
#define FOR(i,s,n) for(int i = s;i < (int)n;i++)
#define RFOR(i,s,n) for(int i = (int)n-1;i >= s;i--)
#define ALL(a) a.begin(),a.end()
#define IN(a, x, b) (a<=x && x<b)
template<class T>inline bool CHMAX(T&a,T b){if(a<b){a = b;return true;}return false;}
template<class T>inline bool CHMIN(T&a,T b){if(a>b){a = b;return true;}return false;}
template<class T>istream&operator >>(istream&is,vector<T>&vec){for(T&x:vec)is>>x;return is;}
template<class T>inline void OUT(T t){cout<<t<<"\n";}
template<class T,class... Ts>inline void OUT(T t,Ts... ts){cout<<t<<" ";OUT(ts...);}
template<typename T=int>vector<T>mv(size_t a){return vector<T>(a);}
template<typename T=int,typename... Ts>auto mv(size_t a,Ts... ts){return vector<decltype(mv<T>(ts...))>(a,mv<T>(ts...));}
template<typename T,typename V>typename enable_if<is_class<T>::value==0>::type FILL(T&t,const V&v){t=v;}
template<typename T,typename V>typename enable_if<is_class<T>::value!=0>::type FILL(T&t,const V&v){for(auto &e:t)FILL(e,v);}
constexpr long long INF = 1e18;

signed main(){
	int N,A,T;
	cin>>N>>T>>A;
	T--;A--;
	vector<vector<int>>g(N);
	REP(i,N-1){
		int a,b;
		cin>>a>>b;
		a--;b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	auto distT = mv(N),distA = distT;
	FILL(distA,INF);
	FILL(distT,INF);
	auto bfs = [&](int s,vector<int>&dist){
		queue<int>que;
		que.push(s);
		dist[s]=0;
		while(que.size()){
			int now = que.front();
			que.pop();
			for(auto e:g[now]){
				if(dist[e]!=INF)continue;
				dist[e]=dist[now]+1;
				que.push(e);
			}
		}
	};
	bfs(A,distA);
	queue<int>que;
	que.push(T);
	distT[T]=0;
	int ans = 0;
	while(que.size()){
		int now = que.front();
		que.pop();
		if(distA[now]<=distT[now])continue;
		CHMAX(ans,distA[now]-distT[now]);
		for(auto e:g[now]){
			if(distT[e]!=INF)continue;
			distT[e]=distT[now]+1;
			que.push(e);
		}
	}
	ans--;
	REP(i,N){
		if(distA[i]==INF)continue;
		CHMAX(ans,distA[i]-1);
	}
	OUT(ans);
}