#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;

vi adj[100005];
int d1[100005];
int d2[100005];

void dfs(int x, int p, int* d)
{
    for (int y : adj[x])
    {
        if (y == p) continue;
        d[y] = d[x] + 1;
        dfs(y, x, d);
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, u, v;
    cin >> n >> u >> v;
    for (int i = 1; i < n; ++i)
    {
        int u, v;
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    dfs(u, 0, d1);
    dfs(v, 0, d2);
    int sol = 0;
    for (int i = 1; i <= n; ++i)
        if (d1[i] < d2[i])
            sol = max(sol, d2[i] - 1);
    cout << sol;
}
