#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

const int INF = 1145141919;
struct edge {
    int to;
    int cost;
};

struct status {
    int cost;
    int v;

    bool operator<(const status &another) const { return cost < another.cost; };

    bool operator>(const status &another) const { return cost > another.cost; };
};

struct status2 {
    int cost;
    int v;
    int remain;

    bool operator<(const status2 &another) const { return cost < another.cost; };

    bool operator>(const status2 &another) const { return cost > another.cost; };
};

vector<int> dijkstra(int s, int n, vector<vector<edge>> &graph) {
    priority_queue<status, vector<status>, greater<>> que;
    vector<int> dis(n, INF);
    dis[s] = 0;
    que.push({0, s});

    while (!que.empty()) {
        status now = que.top();
        que.pop();

        if (dis[now.v] < now.cost)continue;

        for (auto next:graph[now.v]) {
            if (dis[next.to] > dis[now.v] + next.cost) {
                dis[next.to] = dis[now.v] + next.cost;
                que.push({dis[next.to], next.to});
            }
        }
    }

    return dis;
}

int dijkstra2(int s, int n, vector<vector<edge>> &graph, vector<int> &diff) {
    priority_queue<status2, vector<status2>, greater<>> que;
    vector<int> dis(n, INF);
    dis[s] = 0;
    que.push({0, s, diff[s]});

    int ret = 0;

    while (!que.empty()) {
        status2 now = que.top();
        que.pop();

        if (dis[now.v] < now.cost)continue;

        for (auto next:graph[now.v]) {
            if (diff[next.to] < 0)continue;

            if (diff[next.to] == 0)ret = max(ret, dis[now.v] + next.cost);
            else if (dis[next.to] > dis[now.v] + next.cost) {
                dis[next.to] = dis[now.v] + next.cost;
                int nremain = min(now.remain, diff[next.to]);
                que.push({dis[next.to], next.to, nremain});
                ret = max(ret, dis[next.to] + nremain - 1);
            }
        }
    }

    return ret;
}

int main() {
    int n, u, v;
    cin >> n >> u >> v;
    u--, v--;
    vector<vector<edge>> graph(n);
    for (int i = 0; i < n - 1; i++) {
        int from, to;
        cin >> from >> to;
        from--, to--;
        graph[from].push_back({to, 1});
        graph[to].push_back({from, 1});
    }

    vector<int> tak = dijkstra(u, n, graph);
    vector<int> aok = dijkstra(v, n, graph);

    vector<int> possible(n);
    for (int i = 0; i < n; i++) possible[i] = aok[i] - tak[i];
    cout << dijkstra2(u, n, graph, possible) << endl;
    return 0;
}