#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
#define rall(n) n.rbegin(),n.rend()
typedef long long ll;
const ll INF = 2147483647;
const ll MOD = 1e9 + 7;
const double EPS = 1e-10;
const double pi = acos(-1);//3.1415926535897932384626433832795028...
const ll SIZE = 2000005;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
ll fac[SIZE], finv[SIZE], inv[SIZE];
vector<ll>takahashi, aoki;
struct edge { ll to, cost; };
vector<vector<edge>>G;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

ll mod_pow(ll a, ll b) {
	ll res = 1, mul = a;
	for (int i = 0; i < 31; ++i) {
		if (b >> i & 1) {
			res *= mul;
			res %= MOD;
		}
		mul = (mul * mul) % MOD;
	}
	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}

template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T & t, const V & v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T & t, const V & v) {
	for (auto& e : t) fill_v(e, v);
}

template<typename T>
void outp(vector<T>v) {
	for (int i = 0; i < v.size(); ++i) {
		cout << v[i];
		if (i != v.size() - 1) { cout << " "; }
	}
}

double add(double a, double b) {
	if (abs(a + b) < EPS * (abs(a) + abs(b))) { return 0; }
	return a + b;
}

double len(int a, int b, int c, int d) {
	return (double)sqrt((a - c) * (a - c) + (b - d) * (b - d));
}

ll  gcd(ll  a, ll  b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

ll lcm(ll a, ll b) {
	ll  g = gcd(a, b);
	return a / g * b;
}

void dijkstra(ll n) {
	priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>>que;
	fill(takahashi.begin(), takahashi.end(), INF);
	takahashi[n] = 0;
	que.push(pair<ll, ll>(0ll, n));

	while (!que.empty()) {
		pair<ll, ll>p = que.top();
		que.pop();
		ll mon = p.second;
		if (takahashi[mon] < p.first) continue;
		for (int i = 0; i < G[mon].size(); ++i) {
			edge e = G[mon][i];
			if (takahashi[e.to] > takahashi[mon] + e.cost) {
				takahashi[e.to] = takahashi[mon] + e.cost;
				que.push(pair<ll, ll>(takahashi[e.to], e.to));
			}
		}
	}
}

void dijkstra2(ll n) {
	priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>>que;
	fill(aoki.begin(), aoki.end(), INF);
	aoki[n] = 0;
	que.push(pair<ll, ll>(0ll, n));

	while (!que.empty()) {
		pair<ll, ll>p = que.top();
		que.pop();
		ll mon = p.second;
		if (aoki[mon] < p.first) continue;
		for (int i = 0; i < G[mon].size(); ++i) {
			edge e = G[mon][i];
			if (aoki[e.to] > aoki[mon] + e.cost) {
				aoki[e.to] = aoki[mon] + e.cost;
				que.push(pair<ll, ll>(aoki[e.to], e.to));
			}
		}
	}
}

ll a, b, c, ans;
int main() {
	cin >> a >> b >> c;
	--b, --c;
	takahashi.resize(a);
	aoki.resize(a);
	G.resize(a);
	for (int i = 0; i < a - 1; ++i) {
		ll n, m;
		cin >> n >> m;
		--n, --m;
		addedge(n, m, 1);
	}

	dijkstra(b); dijkstra2(c);

	//nodes
	for (int i = 0; i < a; ++i) {
		if (takahashi[i] <= aoki[i]) {
			ans = max(ans, aoki[i]);
		}
	}

	cout << ans - 1 << endl;
}

Measured memory_bytes: 10272