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

vector<vector<int>> g;
vector<int> dp;
void dfs(int u, int p) {
    if (p < 0) dp[u] = 0;
    for (int v: g[u]) if (v != p) {
        dp[v] = dp[u] + 1;
        dfs(v, u);
    }
}

int main() {
    int n; cin >> n;
    int u, v; cin >> u >> v; u--, v--;
    g.resize(n);
    for (int i = 0; i < n - 1; i++) {
        int a, b; cin >> a >> b; a--, b--;
        g[a].emplace_back(b);
        g[b].emplace_back(a);
    }
    dp.resize(n);
    dfs(u, -1);
    auto du = dp;
    dfs(v, -1);
    auto dv = dp;
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (du[i] < dv[i]) ans = max(ans, dv[i] - 1);
    }
    cout << ans << endl;
    return 0;
}
