#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int n, u, v, ans, level[100005];
vector<int> adj[100005];

void dfs1(int root, int parent, int lvl)
{
    level[root] = lvl;
    for (auto x : adj[root])
    {
        if (x == parent) continue;

        dfs1(x, root, lvl + 1);
    }
}

void dfs2(int root, int parent, int dist)
{
    if (level[root] <= dist) return;

    for (auto x : adj[root])
    {
        if (x == parent) continue;

        dfs2(x, root, dist + 1);
    }
    ans = max(ans, level[root] - 1);
}

int main()
{
    cin >> n >> u >> v;
    for (int in = 0; in < n - 1; in++)
    {
        int a, b;
        cin >> a >> b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }

    dfs1(v, -1, 0);
    dfs2(u, -1, 0);

    cout << ans << endl;
}