#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define IFOR(i,a,b) for(int i=(b-1);i>=(a);--i)
#define RPT(i,a,b) for(int i=(a);i<((a)+(b));++i)
#define IRPT(i,a,b) for(int i=((a)+(b)-1);i>=(a);--i)

namespace qweqwe {
  using i32 = int;
  using i64 = long long int;
  using ui32 = unsigned int;
  using ui64 = unsigned long long int;
  using d32 = float;
  using d64 = double;
  using d128 = long double;
  namespace constnumber{//ver 1.1
    constexpr qweqwe::i32  INF_i32 = ((qweqwe::i32)1)<<29;
    constexpr qweqwe::i64  INF_i64 = ((qweqwe::i64)1)<<60;
    constexpr qweqwe::d64  PI_d64 = 3.14159265358979323846264338327950288;
    constexpr qweqwe::d128 PI_d128 = 3.14159265358979323846264338327950288;
    constexpr qweqwe::d64  LN2_d64 = 0.693147180559945309417232121458;
    constexpr qweqwe::d128 LN2_d128 = 0.693147180559945309417232121458;
    constexpr qweqwe::d64  LN10_d64  = 2.302585092994045684017991454684;
    constexpr qweqwe::d128 LN10_d128 = 2.302585092994045684017991454684;
    constexpr qweqwe::d64  GOLDRATIO_d64  = 1.61803398874989484820458683436563811;
    constexpr qweqwe::d128 GOLDRATIO_d128 = 1.61803398874989484820458683436563811;
    constexpr qweqwe::d64  SILVERRATIO_d64  = 2.414213562373095048801688724210;
    constexpr qweqwe::d128 SILVERRATIO_d128 = 2.414213562373095048801688724210;
    constexpr qweqwe::d64  E_d64  = 2.71828182845904523536028747135266249;
    constexpr qweqwe::d128 E_d128 = 2.71828182845904523536028747135266249;
    constexpr qweqwe::d64  OMEGA_d64  = 0.5671432904097838729999686622;
    constexpr qweqwe::d128 OMEGA_d128 = 0.5671432904097838729999686622;
  }
  namespace stdplus{//ver 1.3
    namespace iosplus{
      inline void iosFast(){
        std::cin.tie(0);
        std::ios::sync_with_stdio(false);
      }
      inline void iosDouble(i32 N){
        std::cout << std::fixed << std::setprecision(N);
      }
      template<typename T> std::istream &operator>>(std::istream &is, std::vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
      template<typename T> std::ostream &operator<<(std::ostream &os, const std::vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
      template<typename T> std::ostream &operator<<(std::ostream &os, const std::deque<T> &vec){ os << "deque["; for (auto v : vec) os << v << ","; os << "]"; return os; }
      template<typename T> std::ostream &operator<<(std::ostream &os, const std::set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
      template<typename T> std::ostream &operator<<(std::ostream &os, const std::unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
      template<typename T> std::ostream &operator<<(std::ostream &os, const std::multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
      template<typename T> std::ostream &operator<<(std::ostream &os, const std::unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
      template<typename T1, typename T2> std::ostream &operator<<(std::ostream &os, const std::pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
      template<typename TK, typename TV> std::ostream &operator<<(std::ostream &os, const std::map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
      template<typename TK, typename TV> std::ostream &operator<<(std::ostream &os, const std::unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
    }
    namespace math{
      template<typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
      template<typename T> bool chmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }
      template<typename T1, typename T2> std::pair<T1, T2> operator+(const std::pair<T1, T2> &l, const std::pair<T1, T2> &r) { return std::make_pair(l.first + r.first, l.second + r.second); }
      template<typename T1, typename T2> std::pair<T1, T2> operator-(const std::pair<T1, T2> &l, const std::pair<T1, T2> &r) { return std::make_pair(l.first - r.first, l.second - r.second); }
      inline i64 Bit_i64(i64 x,i32 a){return (((x)>>(a))&((i64)1));}
      inline i32 Bit_i32(i32 x,i32 a){return (((x)>>(a))&((i64)1));}
    }
    namespace others{
      template<typename T> void ndarray(std::vector<T> &vec, int len) { vec.resize(len); }
      template<typename T, typename... Args> void ndarray(std::vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); }
    }
  }
  namespace strlib{
    template<typename T> bool kaibun(T s);//v1.0 20.03.23
  }
  namespace math{
    template<qweqwe::i32 mod> struct modint;//ver 1.0
  }
}

template<qweqwe::i32 mod>
struct qweqwe::math::modint {
  i64 x;
  modint() : x(0) {}
  modint(i64 n) : x(n){
    if(x>=mod) x %= mod;
    else if(x<0) x = (x%mod + mod) % mod;
  }
  static int GetMod() { return mod; }
  operator i64() const { return x;}
  operator i32() const { return (i32)x;}
  constexpr modint &_setval(i64 v) { x = (v >= mod ? v % mod : v); return *this; }
  constexpr modint operator+(const modint &z) const { return modint()._setval((i64)x + z.x); }
  constexpr modint operator-(const modint &z) const { return modint()._setval((i64)x - z.x + mod); }
  constexpr modint operator*(const modint &z) const { return modint()._setval((i64)x * z.x % mod); }
  constexpr modint operator/(const modint &z) const { return modint()._setval((i64)x * z.inv() % mod); }
  constexpr modint operator-() const { return modint()._setval(mod - x); }
  constexpr modint &operator+=(const modint &z) { return *this = *this + z; }
  constexpr modint &operator-=(const modint &z) { return *this = *this - z; }
  constexpr modint &operator*=(const modint &z) { return *this = *this * z; }
  constexpr modint &operator/=(const modint &z) { return *this = *this / z; }
  static i32 get_primitive_root() {
    static i32 primitive_root = 0;
    if (!primitive_root) {
      primitive_root = [&](){
        std::set<i32> fac;
        i32 v = mod - 1;
        for (i64 i = 2; i * i <= v; i++) while (v % i == 0) fac.insert(i), v /= i;
        if (v > 1) fac.insert(v);
        for (i32 g = 1; g < mod; g++) {
          bool ok = true;
          for (auto i : fac) if (modint(g).power((mod - 1) / i) == 1) { ok = false; break; }
          if (ok) return g;
        }
        return -1;
      }();
    }
    return primitive_root;
  }
  constexpr i64 power(i64 n) const {
    i64 ans = 1, tmp = this->x;
    while (n) {
      if (n & 1) ans = ans * tmp % mod;
      tmp = tmp * tmp % mod;
      n /= 2;
    }
    return ans;
  }
  constexpr i64 inv() const { return this->power(mod - 2); }
  constexpr modint operator^(i64 n) const { return modint(this->power(n)); }
  constexpr modint &operator^=(i64 n) { return *this = *this ^ n; }
  bool operator<(const modint &z) const { return x < z.x; }  // To use std::map<ModInt, T>
  friend std::istream &operator>>(std::istream &is, modint &z) { i64 t; is >> t; z = modint(t); return is; }
  friend std::ostream &operator<<(std::ostream &os, const modint &z) { os << z.x;  return os; }
};


constexpr int mod = 1000000007;
using Edges = vector<int>;


void BFS(vector<Edges> &G, vector<int> &pred, vector<int> &dist, vector<int> &checked ,int s, int n){
  for(int v=0; v<n; ++v){
    pred[v] = -1;
    dist[v] = qweqwe::constnumber::INF_i32;
    checked[v] = 0;
  }
  checked[s] = 1;
  dist[s] = 0;
  queue<int> Q;
  Q.push(s);
  while(!Q.empty()){
    auto u = Q.front();
    for(auto v : G[u]){
      if(checked[v]==0){
        dist[v] = dist[u] + 1;
        pred[v] = u;
        checked[v] = 1;
        Q.push(v);
      }
    }
    Q.pop();
    checked[u] = 2;
  }
}

void solve(){
  int n, u, v;
  cin >> n >> u >> v;
  --u; --v;
  vector<Edges> g(n);
  vector<int> par(n), distv(n), distu(n),checked(n);
  FOR(i,0,n-1){
    int a, b;
    cin >> a >> b;
    --a; --b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  BFS(g,par,distv,checked,v,n);
  BFS(g,par,distu,checked,u,n);
  //vector<pair<int,int>> distv_(n);
  //FOR(i,0,n) distv_[i] = pair<int,int>(distv[i],i);
  //sort(distv_.begin(), distv_.end() );
  //reverse( distv_.begin(), distv_.end());
  int ao=0, tk=0, fr=0;
  int ans = 0; int vc = 1;//cout << ao << "," << tk <<","<<fr<<endl;
  FOR(i,0,n){
    int dv = distv[i];
    int du = distu[i];
    if(dv<du) continue;
    ans = max(ans, dv-1);
  }
  cout << ans << endl;
}

qweqwe::i32 main(){
  qweqwe::stdplus::iosplus::iosFast();
  solve();
  return 0;
}


Measured memory_bytes: 7424