#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n); i >= 0; i--)
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;
using ull = unsigned long long;

const int INF = 2100100100;
const int MOD = 1e9 + 7;

// 多次元 vector 生成
template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T> bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

int N;
vector<vector<int>> G;
int A[1001000] = {-1};
int T[1001000] = {-1};
int used_a[1001000] = {-1};
int used_t[1001000] = {-1};

void dfs_a(int node, int depth) {
    used_a[node] = 1;
    A[node] = depth;
    for (auto i : G[node]) {
        if (used_a[i] != 1) {
            dfs_a(i, depth + 1);
        }
    }
}

void dfs_t(int node, int depth) {
    used_t[node] = 1;
    T[node] = depth;
    if (depth < A[node]) {
        for (auto i : G[node]) {
            if (used_t[i] != 1) {
                dfs_t(i, depth + 1);
            }
        }
    }
}

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

    cin >> N;
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    G.resize(N + 2); // adjacency list

    REP(i, N - 1) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    dfs_a(v, 0);
    dfs_t(u, 0);

    int ans = 0;
    REP(i, N) {
        if (A[i] >= T[i]) {
            chmax(ans, T[i]);
        }
    }
    cout << ans << endl;

    return 0;
}
