#include <bits/stdc++.h>
#define pb push_back
#define ff first
#define ss second
#define assign(x,val) memset(x,val,sizeof(x))
#define motherfucker  ios_base::sync_with_stdio(false); cin.tie(NULL);
#define all(x) (x).begin(), (x).end()
#define for0(i,n) for(ll i=0;i<n;++i)
#define for1(i,n) for(ll i=1;i<=n;++i)
#define ford(i,n) for(ll i=n;i>=1;--i)
#define forg(i,a,b) for(ll i=a;i<b;++i)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpi;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpl;
long long mod = 1000000007;
const long double PI = (long double)(3.1415926535897932384626433832795);
const int maxn = (int)1e5;

vector<int> edges[maxn];
int dp[2][maxn] = {0};
bool visi[maxn] = {0};
void dfs(int v, int par, int d, int p){
	visi[v]= true;
	dp[p][v] += d;
	for(auto x : edges[v]){
		if(x==par) continue;
		if(!visi[x])
		dfs(x, v, d + 1, p);
	}
}
void solve(){
	int n, u, v;cin>>n>>u>>v;
	--u;--v;
	for0(i, n-1){
		int x, y;cin>>x>>y;
		--x;--y;
		edges[x].pb(y);
		edges[y].pb(x);
	}
	dfs(u, -1, 0, 0);
	assign(visi, 0);
	dfs(v, -1, 0, 1);
	int ans = 0;
	for0(i,n){
		if(dp[0][i]>=dp[1][i]) continue;
		ans = max(ans, dp[1][i]-1);
	}	
	cout<<ans<<endl;
}
 
int main(){
	motherfucker
	ll t = 1;
	//cin>>t;
	for0(i, t){
		solve();
	}
	return 0;
}