#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF (1ll << 60)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
using vl = vector<ll>;
using vvl = vector<vl>;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

long long gcd(long long a, long long b) {
    for(;;) {
        if(a == 0)
            return b;
        b %= a;
        if(b == 0)
            return a;
        a %= b;
    }
}

long long lcm(long long a, long long b) {
    long long temp = gcd(a, b);
    return temp ? (a / temp * b) : 0;
}

vector<int> E[101010];
int D[101010][2]; //互いの距離
void dfs(int current, int pre, int d, int id) {
    D[cur][id] = d;
    for(auto e : E[cur]) {
        if(e != pre) {
            dfs(e, cur, d + 1, id);
        }
    }
}
int main() {
    int N, A, B;
    cin >> N >> A >> B;
    A--;
    B--;
    REP(i, N - 1) {
        int x, y;
        cin >> x >> y;
        E[x - 1].push_back(y - 1);
        E[y - 1].push_back(x - 1);
    }
    dfs(A, A, 0, 0);
    dfs(B, B, 0, 1);
    int ma = 0;
    REP(i, N) {
        if(D[i][0] < D[i][1]) {
            //後者のほうが遠い点
            ma = max(ma, D[i][1] - 1);
        }
    }
    return 0;
}