#include<bits/stdc++.h>
// use gp_hash_table<int,int,custom_hash> m;
// in place of map
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define rep(i,n) for(int i=0;i<n;++i)
#define repa(i,a,n) for(int i=a;i<n;++i)
#define repr(i,n) for(int i=n-1;i>=0;--i)
#define repba(i,b,a) for(int i=b;i>=a;--i)
#define repab(i,a,b) for(int i=a;i<b;++i)
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define msi map<string,int>
#define mii map<int,int>
#define viip vector<pair<int,pair<int,int> > > 
#define mp make_pair
#define vip vector<pair<int,int> >
#define pb push_back 
#define po pop_back
#define fi first
#define sec second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define s(v) v.size()
ll mod = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());//use rng()%n for numbers in range [0,n-1]
// This custom_hash is for unordered_map 
// use map<int, int, custom_hash> mp;

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
ll gcd(ll a,ll b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int n;
const int maxn = 1e5 + 10;
vi v[maxn];
bool vis[maxn];
vi disa(maxn);
vi dist(maxn);
void dfs(int u,int c){
	vis[u] = true;
	for(auto x:v[u]){
		if(c == 1 && !vis[x]){
			disa[x] = disa[u] + 1;
			dfs(x,1);
		}
		else if(c == 2 && !vis[x]){
			dist[x] = dist[u] + 1;
			dfs(x,2);
		}
	}
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
//	#ifndef ONLINE_JUDGE
  //  	freopen("input.txt", "r", stdin);
  //  	freopen("output.txt", "w", stdout);
//	#endif
	// int n;
	cin>>n;
	int a,t;
	cin>>a>>t;
	int x,y;
	rep(i,n-1){
		cin>>x>>y;
		v[x].pb(y);
		v[y].pb(x);
	}
	disa[a] = 0;
	dist[t] = 0;
	dfs(a,1);
	rep(i,maxn){
		vis[i] = false;
	}
	dfs(t,2);
	int ans = 0;
	// repa(i,1,n+1){
	// 	cout<<disa[i]<<dist[i]<<"\n";
	// }
	repa(i,1,n+1){
		if(disa[i] < dist[i]){
			int temp = dist[i] - disa[i];
			if((int)s(v[i]) == 1){
				continue;
			}
			else if(temp % 2 == 0 && temp != 0){
				ans = max(ans,temp-2+disa[i]);
			}
			// else if(temp % 2 == 1 && )
			else if(temp % 2 == 1){
				ans = max(ans, temp - 1 + disa[i]);
			}
		}
	}
	int min1 =  INT_MAX;
	repa(i,1,n+1){
		if(disa[i] == dist[i]){
			min1 = min(min1,dist[i]);
		}
	}
	if(min1 == INT_MAX)min1 = 0;
	ans = max(ans,min1);
	cout<<ans;
	return 0;
}