#include <bits/stdc++.h>
using namespace std;
#define modulo 998244353
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 100000000

vector<int> get_dis(vector<vector<int>> &E,int start){
	vector<int> dis(N,Inf);
	dis[start] = 0;
	queue<int> Q;
	Q.push(start);
	
	while(Q.size()!=0){
		int from = Q.front();
		Q.pop();
		for(int i=0;i<E[from].size();i++){
			int to = E[from][i];
			if(dis[to]!=Inf)continue;
			dis[to] = dis[from] + 1;
			Q.push(to);
		}
	}
	
	return dis;
}


int main(){
	
	int N;
	cin>>N;
	
	int u,v;
	cin>>u>>v;
	
	vector<vector<int>> E(N,vector<int>());
	
	for(int i=0;i<N;i++){
		int a,b;
		cin>>a>>b;
		E[a].push_back(b);
		E[b].push_back(a);
	}
	
	vector<int> dis_u = get_dis(E,u),dis_v = get_dis(E,v);

	int ans = 0;
	for(int i=0;i<N;i++){
		if(dis_u[i] <= dis_v[i])continue;
		ans = max(ans,dis_v[i]-1);
	}
	
	cout<<ans<<endl;
	
	return 0;
}