#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> using lim = numeric_limits<T>;
template <typename T> istream& operator>>(istream& is, vector<T>& a) { for(T& x : a) { is >> x; } return is; }
template <typename X, typename Y> istream& operator>>(istream& is, pair<X, Y>& p) { return is >> p.first >> p.second; }
template <bool Directed, typename TEdge, bool Index> struct graph {
    using EType = TEdge;
    vector<TEdge> edges;
    vector<vector<int>> adj;
    graph(int n) : adj(n + Index) {}
    graph(int n, int m) : graph(n) { edges.reserve(m << not Directed); }
    TEdge& operator()(int e) { return edges[e]; }
    vector<int>& operator[](int u) { return adj[u]; }
    int size() { return adj.size() - Index; }
    void add_edge(const TEdge& e) {
        adj[e.u].push_back(edges.size());
        edges.push_back(e);
        if(not Directed) {
            adj[e.v].push_back(edges.size());
            edges.push_back(e.reverse());
        }
    }
};
template <typename T> using f = function<T>;
template <typename TEdge> struct dfs_params {
    f<void(int)> pre_node{[](int) -> void {}};
    f<void(int)> pos_node{[](int) -> void {}};
    f<void(TEdge&)> pre_edge{[](TEdge&) -> void {}};
    f<void(TEdge&)> pos_edge{[](TEdge&) -> void {}};
    int root = 0;
};
template <bool Directed, typename TEdge, bool Index, typename TParamsetter = f<void(dfs_params<TEdge>&)>>
vector<int> dfs(graph<Directed, TEdge, Index>& g, const TParamsetter& psetter = [](dfs_params<TEdge>&) {}) {
    static_assert(is_convertible<decltype(psetter), f<void(dfs_params<TEdge>&)>>::value, "psetter must be void(dfs_params<TEdge>&)");
    dfs_params<TEdge> params;
    psetter(params);
    vector<int> component(g.adj.size());
    function<void(int, int)> dfs = [&](int u, int c) {
        component[u] = c;
        params.pre_node(u);
        for(int e : g[u]) if(not component[g(e).v]) {
            params.pre_edge(g(e)), dfs(g(e).v, c), params.pos_edge(g(e));
        }
        params.pos_node(u);
    };
    if(params.root) {
        dfs(params.root, 1);
    } else {
        for(int u = Index, c = 0; u < g.adj.size(); u++) if(not component[u]) {
            dfs(u, ++c);
        }
    }
    return component;
}
constexpr int lg(int x) { return x ? 31 - __builtin_clz(x) : 0; }
template <typename TEdge, bool Index> struct binary_lift {
    vector<int> depth, component;
    vector<vector<int>> p;
    binary_lift(graph<0, TEdge, Index>& g, int root = Index) : depth(g.adj.size()), p(g.adj.size()) {
        component = dfs(g, [&](dfs_params<TEdge>& params) {
            params.pre_edge = [&](TEdge& e) { add_edge(e); };
            params.root = root;
        });
    }
    void add_edge(const TEdge& e) {
        depth.resize(max(int(depth.size()), e.v + 1));
        p.resize(max(int(p.size()), e.v + 1));
        p[e.v].reserve(lg(depth[e.v] = depth[e.u] + 1) + 1);
        p[e.v].push_back(e.u);
        build_ancestors(e.v);
    }
    void build_ancestors(int u) {
        for(int pow2 = 1; pow2 <= lg(depth[u]); pow2++) {
            p[u].push_back(p[p[u][pow2 - 1]][pow2 - 1]);
        }
    }
    int kth_ancestor(int u, int k) {
        return k == 0 ? u : kth_ancestor(p[u][lg(k & -k)], k ^ (k & -k));
    }
    int lca(int u, int v) {
        if(depth[u] > depth[v]) swap(u, v);
        v = kth_ancestor(v, depth[v] - depth[u]);
        for(int pow2 = lg(depth[u]); pow2 >= 0; pow2--) {
            if((1 << pow2) <= depth[u] and p[u][pow2] != p[v][pow2]) {
                u = p[u][pow2], v = p[v][pow2];
            }
        }
        return u == v ? u : p[u][0];
    }
};
template <typename LCA_struct> int dist(LCA_struct& s, int u, int v) {
    return s.depth[u] + s.depth[v] - 2 * s.depth[s.lca(u, v)];
}
struct edge {
    int u, v;
    edge reverse() const { return {v, u}; }
    friend ostream& operator<<(ostream& os, const edge& e) {
        return os << "(" << e.u << ", " << e.v << ")";
    }
};
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, u, v;
    cin >> n >> u >> v;
    graph<0, edge, 1> g(n, n - 1);
    for(int i = 1; i < n; i++) {
        int s, t;
        cin >> s >> t;
        g.add_edge({s, t});
    }
    binary_lift<edge, 1> bl(g, u);
    int ans = 0;
    for(int x = 1; x <= n; x++) {
        if(g[x].size() == 1) {
            int lca = bl.lca(x, v);
            ans = max(ans, dist(bl, lca, u) >= dist(bl, lca, v) ? dist(bl, u, v) / 2 : dist(bl, x, v) - 1);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 22784