#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int n;
vector<int> to[100005];

vector<int> dist;
void dfs(int a, int d = 0, int p = -1) {
	dist[a] = d;
	for (auto& c : to[a]) {
		if (c == p) continue;
		dfs(c, d + 1, a);
	}
}

vector<int> makedist(int a) {
	dist = vector<int>(n);
	dfs(a);
	return dist;
}

int main() {
	cin >> n;
	int u, v;
	cin >> u >> v;
	u--; v--;
	rep(i, n - 1) {
		int a, b; cin >> a >> b;
		a--; b--;
		to[a].emplace_back(b);
		to[b].emplace_back(a);
	}

	vector<int> distT = makedist(u);
	vector<int> distA = makedist(v);

	int ans = 0;
	rep(i, n) {
		if (distT[i] < distA[i]) ans = max(ans, distA[i]);
	}

	cout << ans - 1 << endl;

	return 0;
}
