#include <bits/stdc++.h>
#include <boost/algorithm/string/join.hpp>
#include <boost/range/irange.hpp>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using boost::irange;
using boost::algorithm::join;

typedef long long ll;
typedef unsigned long long ull;
//typedef long double ld;

typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<double,double> pdd;
typedef set<int> si;
typedef set<ll> sll;
typedef vector<int> vi;
typedef vector<pair<int, int > > vii;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef vector<vll> vvll;

constexpr ll MOD = 1e9+7;
template<typename T>constexpr auto inf=numeric_limits<T>::max()/4;
constexpr int INF=inf<int>;
constexpr ll LINF=inf<ll>;

#define Sort(x) sort(begin(x),end(x))
#define Reverse(x) reverse(begin(x),end(x))
#define ABS(a,b) ((a)<(b)?(b)-(a):(a)-(b))
#define nbit(n) (1ull<<(n))
#define _ol3(_1,_2,_3,name,...)name
#define _rep(i,n)_repi(i,0,n)
#define _repi(i,a,b)for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...) _ol3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n) for(int i=n-1;i>=0;--i)
#define REPA(i,v) REP(i,(v).size())

// sort(begin(x), end(x), greater<ll>());
// lower_bound(a.begin(), a.end(), val): a[i] ≥ valである最左の位置
// upper_bound(a.begin(), a.end(), val): a[i] > valである最左の位置

// Returns minimum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmin(T& a, T b) {
  if (a > b) {
    a = b;
  }
  return a;
}

// Returns maximum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmax(T& a, T b) {
  if (a < b) {
    a = b;
  }
  return a;
}

template <typename T>
void dumpContents(const T& v, const string& msg)
{
  cerr << "### " << msg << " ###\n";
  for (const auto& x : v) {
    cerr << x << " ";
  }
  cerr << endl;
}

struct before_main_function {
  before_main_function() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<setprecision(20)<<fixed;
    #define endl "\n"
  }
} before_main_function;

// ========== end of template ==========
constexpr int N_MAX = 1e5;
int N, U, V;

vvi G(N_MAX, vi());

void bfs(int s, pii banned, vi& d) {
  fill(begin(d), end(d), INF);

  queue<int> q;
  q.push(s);
  d[s] = 0;

  while (!q.empty()) {
    int u = q.front(); q.pop();
    for (int v : G[u]) {
      if (d[v] < INF ||
	  (banned.first == v && banned.second == u) ||
	  (banned.first == u && banned.second == v) ) continue;
      d[v] = d[u] + 1;
      q.push(v);
    }
  }
}

int main(int argc, char** argv) {
  cin >> N >> U >> V;
  U--; V--;

  REP(i, N-1) {
    int A, B;
    cin >> A >> B;
    A--; B--;
    G[A].emplace_back(B);
    G[B].emplace_back(A);
  }

  vi d(N);
  // get each distance from V
  pii dummy = {-1, -1};
  bfs(V, dummy, d);
  int ret = 0;
  ret += (d[U]-1)/2;

//cerr << "ret " << ret << endl;

  if (ret == 0) {
    cout << d[U]-1 << endl;
    return 0;
  }

  // Approach U to V by ret
  int cur = U;
  int step = 0;
  while (true) {
    if (step == ret) break;

    step++;
    for (auto x : G[cur]) {
      if (d[x]+1==d[cur]) {
        cur = x;
	break;
      }
    }
  }

//cerr << "cur " << cur << endl;
  if (d[U]%2==0) ret++;
//cerr << "ret2 " << ret << endl;

  // curからVの方向を遮断
  int y = 0;
  for (auto x : G[cur]) {
    if (d[x]+1==d[cur]) {
      y = x;
      break;
    }
  }

  bfs(cur, make_pair(cur, y), d);
  int tmp = 0;
  for(auto x : d) {
    if (x == INF) continue;
    chmax(tmp, x);
  }

  //cerr << "tmp " << tmp << endl;

  cout << ret + tmp << endl;

  return 0;
}


Measured memory_bytes: 6272