#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;

void Main()
{
	int N, u, v;
	std::cin >> N >> v >> u;
	--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<std::pair<int, int>>> max_depth(N);
	boost::dynamic_bitset<> flag(N);
	std::queue<std::pair<int, int>> queue;
	std::vector<int> no_child;
	queue.emplace(-1, u);
	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;
		}
		if (edge[i].size() == 1 && i != u)
		{
			no_child.emplace_back(i);
		}
		else
		{
			for (auto n : edge[i])
			{
				queue.emplace(i, n);
			}
		}
	}
	for (auto s : no_child)
	{
		auto i = parent[s];
		auto p = s;
		while (i)
		{
			if (!max_depth[*i] || max_depth[*i]->first < depth[s])
			{
				max_depth[*i] = std::make_pair(depth[s], p);
			}
			p = *i;
			i = parent[*i];
		}
	}
	auto aoki = 0;
	auto result = 0;
	while (2 < depth[v] - aoki)
	{
		v = *parent[v];
		if (depth[v] == aoki) 
		{
			break;
		}
		++result;
		++aoki;
	}
	while (aoki < depth[v])
	{
		if (!max_depth[v])
		{
			v = *parent[v];
		}
		else
		{
			v = max_depth[v]->second;
		}
		if (depth[v] == aoki)
		{
			break;
		}
		++result;
		++aoki;
	}
	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();
}