#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <stack>
#include <iomanip>
#include <queue>
#include <set>
#include <bitset>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
 
#define ll long long
#define uint unsigned int
#define ull unsigned ll
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define speedhack() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define do(x) for(int i = 1; i <= x; i++){ solve(); }
#define sz(x) (int)x.size()
#define pii pair < int, int >
using namespace std;
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
 
const ll MAXN = 1e18;
const ll SIZE = 1e5 + 2;  //are u sure?
const ll mod = 1e9+7;
vector<int> g[SIZE];
int aokis[SIZE];
bool useda[SIZE];
int takalen = 0;
bool takause[SIZE];
bool takarun[SIZE];
int maxdist = 0;
int takanode = 0;
int takawall = 0;
int runtaka = 0;
int maxrun = 0;
int alternative = 0;
void dfs(int s){
	takause[s] = true;
	for(int i = 0; i < g[s].size(); i++){
		int to = g[s][i];
		if(!takause[to]){
			if(aokis[to] == takalen){
				if(takalen > maxdist){
					maxdist = takalen;
					takanode = s;
					takawall = to;
				}
			}else if(aokis[to] == takalen + 1 && alternative == 0){
				alternative = max(alternative, aokis[to]);
			}
			takalen++;
			dfs(to);
			takalen--;
		}
	}
}

void dfs1(int s){
	maxrun = max(maxrun, runtaka);
	takarun[s] = true;
	for(int i = 0; i < g[s].size(); i++){
		int to = g[s][i];
		if(to != takawall){
			if(!takarun[to]){
				runtaka++;
				dfs1(to);
				runtaka--;
			}
		}
	}
}



void solve(){
	int n, u, v;
	cin >> n >> u >> v;
	for(int i = 1; i < n; i++){
		int a, b;
		cin >> a >> b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	queue<int> q;
	q.push(v);
	while(!q.empty()){
		int s = q.front();
		q.pop();
		useda[s] = true;
		for(int i = 0; i < g[s].size(); i++){
			int to = g[s][i];
			if(!useda[to]){
				aokis[to] = aokis[s] + 1;
				q.push(to);
			}
		}
	}
	dfs(u);
	dfs1(takanode);
	int res = max(maxdist + maxrun, alternative);
	cout << res << endl;
}


int main(){
	speedhack()
	// int it; cin >> it;
	int it = 1;
	do(it);
	return 0;
}