#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T,class U> using P = pair<T,U>;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;

class LCA{
private:
	vector<vector<int>> v;
	vector<vector<int>> parent;
	vector<int> depth;
	void dfs(int n,int m,int d){
		parent[0][n] = m;
		depth[n] = d;
		for(auto x:v[n]){
			if(x!=m) dfs(x,n,d+1);
		}
	}
public:
	LCA(int N,int root,vector<vector<int>>& tree){
		v = tree;
		parent = vector<vector<int>>(20,vector<int>(N,0));
		depth = vector<int>(N,0);
		dfs(root,-1,0);
		for(int j=0;j+1<20;j++){
			for(int i=0;i<N;i++){
				if(parent[j][i]<0) parent[j+1][i] = -1;
				else parent[j+1][i] = parent[j][parent[j][i]];
			}
		}
	}
	int lca(int n,int m){
		if(depth[n]>depth[m]) swap(n,m);
		for(int j=0;j<20;j++){
			if((depth[m]-depth[n]) >> j&1) m = parent[j][m];
		}
		if(n==m) return n;
		for(int j=19;j>=0;j--){
			if(parent[j][n]!=parent[j][m]){
				n = parent[j][n];
				m = parent[j][m];
			}
		}
		return parent[0][n];
	}
	int dep(int n){return depth[n];}
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,U,V;
    cin >> N >> U >> V;
    U--; V--;
    vvec<int> g(N);
    for(int i=0;i<N-1;i++){
        int a,b;
        cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    LCA lca(N,0,g);
    vec<int> distU(N,0),distV(N,0);
    auto dfs = [&](auto& self,int cur,int par,vec<int>& dist)-> void{
        for(auto& e:g[cur]) if(e!=par){
            dist[e] = dist[cur]+1;
            self(self,e,cur,dist);
        }
    }; 

    int inf = 1e9;
    int ans = 0,ans2 = inf;
    dfs(dfs,V,-1,distV);
    dfs(dfs,U,-1,distU);
    for(int i=0;i<N;i++){
        if(distU[i]<distV[i]){
            int d = distV[i]-distU[i];
            ans = max(ans,distU[i]+(d-1)/2*2);
        }else if(distU[i]==distV[i]) ans2 = min(ans2,distU[i]);
    }
    if(ans2!=inf) ans = max(ans,ans2);
    cout << ans << endl;
}
