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

typedef long long ll;
const double EPS = 1e-9;
typedef vector<ll> vecl;
typedef pair<ll, ll> pairl;

template<typename T, typename U>
using mapv = map<T,vector<U>>;

#define ALL(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }

#define MOD097 1000000007

///// For Debug

#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
// vector
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec) is >> x;
    return is;
}
// pair
template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &pair_var) {
    os << "(" << pair_var.first << ", " << pair_var.second << ")";
    return os;
}
// vector
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
// map
template <typename T, typename U>
ostream &operator<<(ostream &os, map<T, U> &map_var) {
    os << "{";
    repi(itr, map_var) {
        os << *itr;
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
// set
template <typename T>
ostream &operator<<(ostream &os, set<T> &set_var) {
    os << "{";
    repi(itr, set_var) {
        os << *itr;
        itr++;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
 
#define DUMPOUT cerr
 
void dump_func() {
    DUMPOUT << endl;
}
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&... tail) {
    DUMPOUT << head;
    if (sizeof...(Tail) > 0) {
        DUMPOUT << ", ";
    }
    dump_func(std::move(tail)...);
}

// 提出時はコメントアウト
// #define LOCAL
#define DEBUG_

#ifndef LOCAL
#undef DEBUG_
#endif

#ifdef DEBUG_

#define DEB
#define dump(...)                                                              \
    DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
            << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
            << endl                                                            \
            << "    ",                                                         \
        dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)

#endif

//////////

class Tree {
	private:
		vector<vecl> G;
		vector<vecl> parents;
		vector<ll> depths;
		ll LOG;
	
	public: 
		Tree(ll V) {
			LOG = log2(V+10)+10;
			parents.resize(LOG+1, vecl(V+1));
			depths.resize(V+1);
			G.resize(V+1);
		}

		void add(ll x,ll y) {
			G[x].push_back(y);
			G[y].push_back(x);
		}

		void build(ll root=1) {
			ll V = G.size()-1;
			dfs(root, -1, 0);
			rep(k, LOG) {
				rep(v,V) {
					if (parents[k][v] < 0)
						 parents[k + 1][v] = -1;
					else 
						parents[k + 1][v] = parents[k][parents[k][v]];
				}
			}
		}

		void dfs(ll v, ll parent, ll depth) {
			parents[0][v] = parent;
			depths[v] = depth;
			for (auto &i : G[v])
			{
				if (i != parent) dfs(i, v, depth+1);
			}
		}

		vecl leaves() {
			ll V = G.size()-1;
			vecl res;
			rep(i,V) {
				if (G[i].size() == 1) res.push_back(i);
			}
			return res;
		}
	
		ll lca(ll u, ll v) {
			if (depths[u] > depths[v]) swap(u, v);
			rep(k, LOG) {
				if ((depths[v] - depths[u]) >> k & 1)
				v = parents[k][v];
			}
			if (u == v) return u;
			for (ll k = LOG; k >= 0; k--) {
				if (parents[k][u] != parents[k][v])
				{
					u = parents[k][u];
					v = parents[k][v];
				}
			}
			return parents[0][u];
		}
	
		ll distance(ll u, ll v) {
			ll t = lca(u, v);
			return depths[u] + depths[v] - 2*depths[t];
		}
};



int main() {
    #ifdef LOCAL
    ifstream in("../../Atcoder/input.txt");
    cin.rdbuf(in.rdbuf());
    #endif

	ll N,u,v;
	cin>>N>>u>>v;

	u--;v--;
	Tree tree(N);
	rep(i,N-1) {
		ll a,b;
		cin>>a>>b;

		a--;b--;
		tree.add(a,b);
	}

	tree.build(v);
	auto leaves = tree.leaves();

	ll ans = 0;
	for (auto &leaf : leaves) {
		ll lca = tree.lca(leaf,u);

		ll lca_aoki = tree.distance(v,lca);	
		ll lca_taka = tree.distance(u,lca);

		ll dist_aoki = tree.distance(v,leaf);	
		ll dist_taka = tree.distance(u,leaf);

		if (lca_aoki > lca_taka) {
			ll delta = dist_aoki - 1;
			dump(delta);
			chmax(ans,delta);
		}
	}

	cout << ans << endl;

    return 0;
}


Measured memory_bytes: 36392