#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")

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

using namespace std;
using namespace __gnu_pbds;

#define ll long long int
#define pb push_back
#define mp make_pair
#define ld long double
#define sz(a) (ll)(a).size()
#define endl "\n"

typedef tree<pair<ll,ll> ,null_type,less<pair<ll,ll> >,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//K-th smallest
//cout << k << "kth smallest: " << *A.find_by_order(k-1) << endl;
//NO OF ELEMENTS < X
//cout << "No of elements less than " << X << " are " << A.order_of_key(X) << endl;

const int MAXN = 1e5 + 5;

vector<ll>adj[MAXN];
ll p[MAXN][22], parent[MAXN], level[MAXN], n, u, v, a, b, res;

void precom()                                        // for calculating 2^k th parent of every node
{
	for(int i = 0 ; i < n ; i++)
		for(int j = 0 ; (1ll << j) < n ; j++)
			p[i][j]=-1;
	for(int i = 0 ; i < n ; i++)
		p[i][0] = parent[i];
	for(int j = 1 ; (1ll << j) < n ; j++)
		for(int i = 0 ; i < n ; i++)
			if(p[i][j - 1] != -1)
				p[i][j] = p[p[i][j - 1]][j - 1];
}

ll lca(ll u, ll v)
{
	if(min(level[u], level[v]) == level[u]) swap(u, v);
	ll dist = level[u] - level[v];
	while(dist)
	{
		ll raise = log2(dist);
		u=p[u][raise];
		dist -= (1ll<<raise);
	}
	if(u == v) return u;
	for(int j = log(MAXN) ; j >= 0 ; j--)
	{
		if(p[u][j] != -1 && p[u][j] != p[v][j])
		{
			u = p[u][j];
			v = p[v][j];
		}
	}
	return parent[u];
}

void dfs(ll node, ll par, ll lev)                              // dfs to set parent and calculate levels
{
	level[node] = lev;
	for(auto it : adj[node])
	{
		if(it == par) continue;
		parent[it] = node;
		dfs(it, node, lev + 1);
	}		
}

ll dist(ll x, ll y)
{
	return level[x] + level[y] - 2 * level[lca(x, y)];
}

void dfs1(ll node, ll par)
{
	for(auto it : adj[node])
	{
		if(it == par) continue;
		dfs1(it, node);
	}
	ll x1 = dist(u, node);
	ll x2 = dist(v, node);
	if(x1 < x2) res = max(res, x2 - 1);	
}

int main()
{
	std::ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

 	cin >> n >> u >> v;
 	u -= 1; v -= 1;
 	for(int i=0;i<n-1;i++)
 	{
 		cin >> a >> b;
 		adj[a - 1].pb(b - 1);	
 		adj[b - 1].pb(a - 1);	
 	}
 	if(u == v)
 	{
 		cout << 0 << endl;
 		return 0;
 	}
 	dfs(0, -1, 0);
 	precom();
 	dfs1(0, -1);
 	cout << res << endl;
    return 0;
}