#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int MAXN = 1e5 + 5;
int N, U, V; 
vector<int> adj[MAXN];

void bfs(vector<int> &dist, int src) {
	queue<int> Q;
	dist[src] = 0;
	Q.push(src);
	while(!Q.empty()) {
		int here = Q.front(); Q.pop();
		for(auto &next : adj[here]) {
			if(dist[next] == INT_MAX) {
				dist[next] = dist[here] + 1;
				Q.push(next);
			}
		}
	}
}

int main() {
	cin >> N >> U >> V;
	--U; --V;
	for(int i = 0; i < N - 1; ++i) {
		int a, b; cin >> a >> b;
		adj[a - 1].push_back(b - 1);
		adj[b - 1].push_back(a - 1);
	}
	vector<int> UD(N, INT_MAX), VD(N, INT_MAX);
	bfs(UD, U);
	bfs(VD, V);
	int maxD = 0;
	for(int i = 0; i < N; ++i) {
		if(VD[i] > UD[i]) maxD = max(maxD, VD[i]);
	}
	cout << maxD - 1 << endl;
}