#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <random>
#include <chrono>

using namespace std;
using namespace __gnu_pbds;

#define endl '\n'

typedef long long ll;
typedef pair<int, int> pii;
//typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int maxn = 1e5 + 5;

vector<int> g[maxn];
int n;

vector<int> bfs(int u){
	vector<int> d(n, -1);
	d[u] = 0;
	queue<int> Q;
	Q.push(u);
	while(!Q.empty()){
		u = Q.front();Q.pop();
		for(auto &v : g[u])
			if(d[v] == -1){
				d[v] = d[u] + 1;
				Q.push(v);
			}
	}
	return d;
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	int x, y;

	cin >> n >> x >> y;
	
	x--, y--;
	
	for(int i = 1; i < n; i++){
		int a, b;
		cin >> a >> b;
		a--, b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	
	auto d2 = bfs(y);
	
	vector<int> d(n, -1);
	d[x] = 0;
	queue<int> Q;
	Q.push(x);
	while(!Q.empty()){
		int u = Q.front();Q.pop();
		for(auto &v : g[u])
			if(d[v] == -1 && d[u] + 1 <= d2[v]){
				d[v] = d[u] + 1;
				if(d[v] < d2[v])
					Q.push(v);
			}
	}
	
	int ans = 0;
	for(int i = 0; i < n; i++)
		ans = max(ans, d[i]);
	
	cout << ans << endl;
	
	return 0;
}
