#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


class tree {		// implementation of recurvie programming
	int ct;
public:
	int nn, root;				// # of nodes, id of root
	vector<int> parent;			// parent of each node; -1 if unassigned
	vector<int> depth;			// depth of each node
	vector<int> sz;				// subtree size of each node 
	vector<vector<int>> adj;	// adjacency list from each node
	vector<vector<int>> sons;	// sons list from each node

	// for cartesian_decomposition
	vector<int> in, out;		// starting and ending position of a subtree
	vector<int> pos;			// inorder of DFS

	// for LCA sparse table
	vector<vector<int>> pred;
	int MAXLEVEL;

	tree(int n) {
		nn = n;
		adj.clear();
		adj.resize(n);
	}

	void add_path(int a, int b) {
		adj[a].push_back(b);
		adj[b].push_back(a);
	}

	void add_directed_path(int a, int b) {
		adj[a].push_back(b);
	}

	void dfs_set_root(int id, bool cartesian_decomposition = false) {	// internal
		if (cartesian_decomposition) {
			in[id] = ct;
			pos[ct] = id;
			ct++;
		}

		sz[id]++;

		for (auto p : adj[id]) {
			if (parent[p] == -1) {
				parent[p] = id;
				depth[p] = depth[id] + 1;
				dfs_set_root(p, cartesian_decomposition);
				sz[id] += sz[p];

				sons[id].push_back(p);
			}
		}

		if (cartesian_decomposition) out[id] = ct - 1;
	}

	void set_root(int id, bool cartesian_decomposition = false) {		// set root of the tree and calculate necessary info
		if (cartesian_decomposition) {
			in.resize(nn);
			out.resize(nn);
			pos.resize(nn);
			ct = 0;
		}

		parent.assign(nn, -1);
		depth.assign(nn, -1);
		sz.assign(nn, 0);
		sons.clear();
		sons.resize(nn);

		parent[id] = 0;
		depth[id] = 0;
		dfs_set_root(id, cartesian_decomposition);
	}

	void prep_LCA() {		// prepare the sparse table for LCA calculation
		MAXLEVEL = 1;
		while ((1 << MAXLEVEL) < nn) MAXLEVEL++;
		MAXLEVEL++;

		pred.assign(MAXLEVEL, vector<int>(nn, 0));
		pred[0] = parent;
		
		int i, j, k;
		for (i = 1; i < MAXLEVEL; i++) {
			for (j = 0; j < nn; j++) {
				if (pred[i - 1][j] != -1) pred[i][j] = pred[i - 1][pred[i - 1][j]];
			}
		}
	}

	int LCA(int a, int b) {		// get the LCA of a and b, need to call set_root() and prep_LCA() first
		int da = depth[a], db = depth[b];

		if (da > db) {
			swap(da, db);
			swap(a, b);
		}

		int i, j, k;
		for (i = MAXLEVEL - 1; i >= 0; i--) {
			if (db - (1 << i) >= da) {
				db -= (1 << i);
				b = pred[i][b];
			}
		}

		if (a == b) return a;

		for (i = MAXLEVEL - 1; i >= 0; i--) {
			if (pred[i][a] != pred[i][b]) {
				a = pred[i][a];
				b = pred[i][b];
			}
		}

		return parent[a]; 
	}

	int get_distance(int a, int b) {
		int c = LCA(a, b);
		int ans = depth[a] + depth[b] - 2 * depth[c];
		return ans;
	}
};



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

	//freopen("input.txt", "r", stdin);

	int n, a, b, i, j, k, aa, bb, ans, dd;
	cin >> n >> a >> b;

	tree tr(n + 1);
	for (i = 0; i < n - 1; i++) {
		cin >> aa >> bb;
		tr.add_path(aa, bb);
	}

	vector<int> dista, distb, distleaf;

	tr.set_root(a, true);
	dista = tr.depth;

	tr.set_root(b, true);
	distb = tr.depth;

	tr.prep_LCA();
	dd = tr.get_distance(a, b);

	queue<int> q;
	distleaf.assign(n + 1, -1);

	for (i = 1; i <= n; i++) {
		if (tr.adj[i].size() == 1) {
			q.push(i);
			distleaf[i] = 0;
		}
	}

	while (!q.empty()) {
		int id = q.front();
		q.pop();

		for (auto p : tr.adj[id]) {
			if (distleaf[p] == -1) {
				distleaf[p] = distleaf[id] + 1;
				q.push(p);
			}
		}
	}

	if ((tr.adj[a].size() == 1) && (tr.adj[a][0] == b)) ans = 0;
	else {
		ans = 0;
		int minn = n * 3;
		for (i = 1; i <= n; i++) {
			if (dista[i] > distb[i]) continue;
			if (dista[i] == distb[i]) minn = min(minn, dista[i]);
			else ans = max(ans, distb[i] - 1);
		}
		if ((minn < n * 3) && (ans < minn)) ans = minn;
	}


	cout << ans << "\n";


	return 0;
}



Measured memory_bytes: 29304