#include <bits/stdc++.h>
using namespace std;
using cpx = complex<double>;
using namespace std::literals;
using Int = long long;
using Double = long double;
#ifdef __GNUG__
#define _GLIBCXX_DEBUG
#endif
#define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++)
#define reps(i, n) for (int i = 1, i##_len = (int)(n); i <= i##_len; i++)
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define LEN(x) ((int)(x).length())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define F first
#define S second
#define perm(c)   \
    sort(ALL(c)); \
    for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c)))
vector<Int> IntsIn(int n) {
    auto v = vector<Int>(0);
    for (int i = 0; i < n; i++) {
        Int a;
        cin >> a;
        v.push_back(a);
    }
    return v;
}
template <typename T>
void Puts(T x) {
    cout << x << endl;
}
void setPrecision(int num = 20) {
    std::cout << std::fixed << std::setprecision(num);
}
template <typename T>
T Max(T a) {
    return a;
}
template <typename T, typename... Args>
T Max(T a, Args... args) {
    return std::max(Max(args...), a);
}
template <typename T>
T Min(T a) {
    return a;
}
template <typename T, typename... Args>
T Min(T a, Args... args) {
    return std::min(Min(args...), a);
}
template <typename T>
bool vector_contains(std::vector<T> vec, T value) {
    return (std::distance(vec.begin(), std::find(vec.begin(), vec.end(), value)) != vec.size());
}
template <typename T>
long indexOf(std::vector<T> &vec, const T &value) {
    auto result = std::distance(vec.begin(), std::find(vec.begin(), vec.end(), value));
    return ((long)result == (long)vec.size()) ? -1 : result;
}
template <typename T>
void removeAt(std::vector<T> &vec, unsigned int index) {
    vec.erase(vec.begin() + index);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &value) {
    std::fill((T *)array, (T *)(array + N), value);
}
template <typename T>
struct countMap {
    map<T, Int> dict;
    countMap() {
        dict = map<T, Int>();
    }
    Int operator[](T key) {
        if (dict.find(key) != dict.end()) {
            return dict[key];
        } else {
            return 0;
        }
    }
    // key に対応する値があれば1増加させる，なければキーを新設して1をセット
    void incremntFor(T key) {
        if (dict.find(key) != dict.end()) {
            dict[key]++;
        } else {
            dict.emplace(key, 1);
        }
    }
    // for (auto &p: dict) でループできるように
    auto begin() const {
        return dict.begin();
    }
    auto end() const {
        return dict.end();
    }
};
struct Node {
    vector<Int> adjacents;
    Int lenFromA = -1;
    Int lenFromB = -1;
    bool flag;
};
int main() {
    Int n, u, v;
    cin >> n >> u >> v;
    u--;
    v--;
    auto nodes = vector<Node>(n);
    rep(i, n - 1) {
        Int a, b;
        cin >> a >> b;
        a--;
        b--;
        nodes[a].adjacents.PB(b);
        nodes[b].adjacents.PB(a);
    }
    function<void(Int, Int, Int)> dfsA = [&](Int index, Int parent, Int distance) {
        auto &node = nodes[index];
        node.lenFromA = distance;
        for (auto &nextIndex : node.adjacents) {
            if (nextIndex == parent) continue;
            dfsA(nextIndex, index, distance + 1);
        }
    };
    function<void(Int, Int, Int)> dfsB = [&](Int index, Int parent, Int distance) {
        auto &node = nodes[index];
        node.lenFromB = distance;
        node.flag = (node.lenFromA < node.lenFromB);
        for (auto &nextIndex : node.adjacents) {
            if (nextIndex == parent) continue;
            dfsB(nextIndex, index, distance + 1);
        }
    };
    dfsA(u, -1, 0);
    dfsB(v, -1, 0);
    Int result = 0;
    for (auto &node : nodes) {
        if (node.flag) {
            result = max(result, node.lenFromB);
        }
    }
    Puts(result - 1);
}


Measured memory_bytes: 15872