#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define all(v) v.begin(),v.end()
#define vi vector<int> 
#define mod 1000000007
#define inf 1e17
#define fs first
#define ss second

template <typename T> 
void amax(T& x, T y) 
{ 
    if( x < y) x = y;
} 

template <typename T> 
void amin(T& x, T y) 
{ 
    if( x > y) x = y;
} 
////////////////////////////////////////////////////////////////////////////////
int n;
vector<int> g[100005];


void dfs(int cur,int d,int par,auto& dist,auto& vis){
	vis[cur] = true; 
	dist[cur] = d;
	
	for(auto i: g[cur]){
	  if( i != par){
	     dfs(i,d+1,cur,dist,vis);
       }
    }
}


vector<int> distf(int u){
	
	vector<int> dist(n);
	vector<bool> vis(100005,false);
	
	dfs(u,0,-1,dist,vis);
	
	return dist;
}


int main(){
    
   
    cin >> n; 
    
    int t,a;
    cin >> t >> a;
    
    for(int i=0;i<n-1;i++) {
		int u,v;
		cin >> u >> v;
		g[u].push_back(v);
		g[v].push_back(u);		
	}   
   
    vector<int> dt = distf(t);
    vector<int> da = distf(a);
         
    int ans = 0;
    
    for(int i =1;i<=n;i++){
	     if( dt[i] < da[i]) ans = max(ans,da[i]);	
	}
    cout << ans - 1 << endl;
     
}
