#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define IO(i, o) freopen(i, "r", stdin), freopen(o, "w", stdout)
#define MOD 1000000007;

using namespace std;
using namespace __gnu_pbds;
//typedef tree<TYPE, null_type, less<TYPE>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
//typedef tree<TYPE, null_type, less_equal<TYPE>, rb_tree_tag, tree_order_statistics_node_update> indexed_multiset;

int n, u, v, alt, cld[100001], bef[100001], dst[100001];
vector<int> adj[100001];

int prelim(int vtx, int pre, int aok){
	bef[vtx] = pre;
	dst[vtx] = aok++;
	int mx = 0;
	for(auto i : adj[vtx])
		if(i != pre) mx = max(mx, prelim(i, vtx, aok));
	cld[vtx] = mx;
	return mx + 1;
}

int trav(int vtx, int cnt){
	if(dst[bef[vtx]] >= cnt + 1) alt = cnt + 1; 
	if(dst[bef[vtx]] > cnt + 1) return trav(bef[vtx], cnt + 1);
	else return cld[vtx] + cnt;
}

int main(){
	//IO("input.txt", "output.txt");
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n >> u >> v;
	for(int i = 0; i < n - 1; i++){
		int a, b;
		cin >> a >> b;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	prelim(v, 0, 0);
	cout << max(alt, trav(u, 0)) << "\n";
 	return 0;
}