#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
#include <set>
#include <ctime>
#include <tuple>
#include <bitset>
#include <assert.h>
#include <deque>
#include <functional>
using namespace std;
typedef long long ll;

#define fi first
#define se second
#define rep(i, n) for (ll i = 0; i < n; i++)
#define debugA cerr << "AAAAA" << endl
#define debug_ cerr << "-------------" << endl
#define debug(x) cerr << #x << ": " << x << endl
#define debug_vec(v)                   \
    cout << #v << endl;                \
    for (int i = 0; i < v.size(); i++) \
    {                                  \
        cout << v[i] << " ";           \
    }                                  \
    cout << endl;
#define debug_vec2(v)                         \
    cout << #v << endl;                       \
    for (int i = 0; i < v.size(); i++)        \
    {                                         \
        for (int j = 0; j < v[i].size(); j++) \
        {                                     \
            cout << v[i][j] << " ";           \
        }                                     \
        cout << endl;                         \
    }

template <typename T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}

template <typename T>
bool chmin(T &a, const T &b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}

using Graph = vector<vector<int>>;
using P = pair<int, int>;
using P1 = pair<int, pair<int, int>>; // クラスカル法とかで、{cost, {from, to}}的に使う。
const ll LINF = 1001002003004005006ll;
const ll INF = 1001001001;
const double pi = acos(-1);

int main()
{
    int n, u, v;
    cin >> n >> u >> v;
    u--;
    v--;
    Graph G(n);
    for (int i = 0; i < n - 1; i++)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    vector<int> dist(n, -1);
    dist[u] = 0;
    queue<int> que;
    que.push(u);
    while (!que.empty())
    {
        int x = que.front();
        que.pop();
        for (auto ver : G[x])
        {
            if (dist[ver] == -1)
            {
                dist[ver] = dist[x] + 1;
                que.push(ver);
            }
        }
    }
    int ans = 0;
    if (dist[v] % 2 == 0)
    {
        ans += (dist[v] - 1) / 2;
        ans++;
    }
    else
    {
        ans += (dist[v] - 1) / 2;
    }
    // debug(ans);
    vector<int> re_route; // vスタートでuに行くroute
    int ver = v;
    while (true)
    {
        if (dist[ver] == 0)
        {
            re_route.push_back(ver);
            break;
        }
        for (auto x : G[ver])
        {
            if (dist[x] == dist[ver] - 1)
            {
                re_route.push_back(ver);
                ver = x;
            }
        }
    }
    int sz = re_route.size();
    vector<int> route(sz); // uスタートでvがゴール
    for (int i = 0; i < sz; i++)
    {
        route[i] = re_route[sz - 1 - i];
    }
    // debug_vec(route);

    int start = route[(dist[v] - 1) / 2];
    int ng_node = route[(dist[v] - 1) / 2 + 1];
    // debug(start);

    // uとvの間の経路を切断。
    Graph G1(n);
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < G[i].size(); j++)
        {
            if (i == ng_node || G[i][j] == ng_node)
            {
                continue;
            }
            else
            {
                G1[i].push_back(G[i][j]);
            }
        }
    }

    queue<int> que1;
    vector<int> dist1(n, -1);
    dist1[start] = 0;
    que1.push(start);
    while (!que1.empty())
    {
        int x = que1.front();
        que1.pop();
        for (auto y : G1[x])
        {
            if (dist1[y] == -1)
            {
                dist1[y] = dist1[x] + 1;
                que1.push(y);
            }
        }
    }
    int MAX = 0;
    for (int i = 0; i < n; i++)
    {
        MAX = max(MAX, dist1[i]);
    }
    ans += MAX;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 15384