#include "bits/stdc++.h"
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/operators.hpp>
#include <boost/dynamic_bitset.hpp>

namespace adaptor = boost::adaptors;
using index_t = std::size_t;

int DFS(int i, int p, std::vector<std::set<int>> const &edge, std::vector<int> const &depth, std::vector<boost::optional<int>> &next)
{
	int max = -1;
	for (auto n : edge[i])
	{
		if (n == p)
		{
			continue;
		}
		auto r = DFS(n, i, edge, depth, next);
		if (max < r)
		{
			next[i] = n;
			max = r;
		}
	}
	return max == -1 ? depth[i] : max;
}

void Main()
{
	int N, u, v;
	std::cin >> N >> u >> v;
	--u;
	--v;
	std::vector<std::set<int>> edge(N);
	for (auto _ : boost::irange(0, N - 1))
	{
		int a, b;
		std::cin >> a >> b;
		--a;
		--b;
		edge[a].emplace(b);
		edge[b].emplace(a);
	}
	std::vector<boost::optional<int>> parent(N);
	std::vector<int> depth(N);
	std::vector<boost::optional<int>> next(N);
	boost::dynamic_bitset<> flag(N);
	std::queue<std::pair<int, int>> queue;
	queue.emplace(-1, v);
	while (queue.size())
	{
		int p, i;
		std::tie(p, i) = queue.front();
		queue.pop();
		if (flag[i])
		{
			continue;
		}
		flag[i] = true;
		if (p == -1)
		{
			depth[i] = 0;
		}
		else
		{
			depth[i] = depth[p] + 1;
			parent[i] = p;
		}
		for (auto n : edge[i])
		{
			queue.emplace(i, n);
		}
	}
	DFS(v, -1, edge, depth, next);
	auto aoki = 0;
	auto result = 0;
	while (2 < depth[u] - aoki)
	{
		u = *parent[u];
		++result;
		++aoki;
	}
	while (aoki < depth[u])
	{
		if (!next[u])
		{
			u = *parent[u];
		}
		else
		{
			u = *next[u];
		}
		if (depth[u] == aoki)
		{
			break;
		}
		else
		{
			++result;
			++aoki;
		}
	}
	lib::print::debug_range(next);
	std::cout << result << std::endl;
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}