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

const int DMAX = 1e5 + 10;

int n, a, b;

vector <int> V[DMAX];

int distA[DMAX];
int distB[DMAX];

void dfs(int node, int father, int dist[]);

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

    int i,x,y;

    cin >> n >> a >> b;

    for (i = 1; i < n; i++) {
        cin >> x >> y;
        V[x].push_back(y);
        V[y].push_back(x);
    }

    dfs(a, 0, distA);
    dfs(b, 0, distB);

    int best = 0;
    for (i = 1; i <= n; i++)
        if (distA[i] <= distB[i])
            best = max(best, distB[i]);

    cout << best - 2 << '\n';
    return 0;
}
void dfs(int node, int father, int dist[]){
    dist[node] = dist[father] + 1;
    for (auto& nghb : V[node])
        if (nghb != father)
            dfs(nghb, node, dist);
}
