q#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
template<class T, class Compare = less<T> >
using MaxHeap = priority_queue<T, vector<T>, Compare>;
template<class T, class Compare = greater<T> >
using MinHeap = priority_queue<T, vector<T>, Compare>;
using llong = long long;

template< typename G >
struct DoublingLowestCommonAncestor {
    const int LOG;
    vector< int > dep;
    const G &g;
    vector< vector< int > > table;

    DoublingLowestCommonAncestor(const G &g) : g(g), dep(g.size()), LOG(32 - __builtin_clz(g.size())) {
        table.assign(LOG, vector< int >(g.size(), -1));
    }

    void dfs(int idx, int par, int d) {
        table[0][idx] = par;
        dep[idx] = d;
        for(auto &to : g[idx]) {
            if(to != par) dfs(to, idx, d + 1);
        }
    }

    void build() {
        dfs(0, -1, 0);
        for(int k = 0; k + 1 < LOG; k++) {
            for(int i = 0; i < table[k].size(); i++) {
                if(table[k][i] == -1) table[k + 1][i] = -1;
                else table[k + 1][i] = table[k][table[k][i]];
            }
        }
    }

    int query(int u, int v) {
        if(dep[u] > dep[v]) swap(u, v);
        for(int i = LOG - 1; i >= 0; i--) {
            if(((dep[v] - dep[u]) >> i) & 1) v = table[i][v];
        }
        if(u == v) return u;
        for(int i = LOG - 1; i >= 0; i--) {
            if(table[i][u] != table[i][v]) {
                u = table[i][u];
                v = table[i][v];
            }
        }
        return table[0][u];
    }
};

llong n, u, v;
llong a, b;
vector<vector<llong> > to_edge(100005);
llong dp[100005] = {-1, -1};

pair<int, int> dfs(int idx, int par) {
    pair<int, int> ret(0, idx);

    for (auto &e:to_edge[idx]) {
        if (e == par) continue;
        auto cost = dfs(e, idx);
        cost.first++;
        ret = max(ret, cost);
    }
    return ret;
}

void d(int idx, int par) {
    dp[idx]++;
    for (auto &e:to_edge[idx]) {
        if (e == par) continue;
        d(e, idx);
    }
}

pair<int, int> diam() {
    auto p = dfs(1, -1);
    auto q = dfs(p.second, -1);
    return {p.second, q.second};
}

int main() {
    cin >> n >> u >> v;
    --u;--v;
    for (int i = 0; i < n; i++) {
        cin >> a >> b;
        --a; --b;
        to_edge[a].push_back(b);
        to_edge[b].push_back(a);
    }
    d(1, -1);
    DoublingLowestCommonAncestor<decltype(to_edge)> lca(to_edge);
    auto node = diam();

    llong n1 = node.first;
    llong n2 = node.second;
    llong ans = 0;

    {
        int w = lca.query(n1, u);
        if (dp[u] - dp[w] <= dp[v] + dp[w] - dp[lca.query(v, w)] * 2) {
            ans = max(dp[u] + dp[v] - dp[lca.query(u, v)] * 2, ans);
        }
        else {
            ans = max(ans, dp[v] + dp[n1] - dp[lca.query(v, n1)] * 2);
        }
    }
    {
        int w = lca.query(n2, u);
        if (dp[u] - dp[w] <= dp[v] + dp[w] - dp[lca.query(v, w)] * 2) {
            ans = max(dp[u] + dp[v] - dp[lca.query(u, v)] * 2, ans);
        }
        else {
            ans = max(ans, dp[v] + dp[n2] - dp[lca.query(v, n2)] * 2);
        }
    }

    cout << ans << endl;

    return 0;
}
