#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
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;
}
template <class T>
inline void printv(vector<T>& v) {
  int n = (int)v.size();
  for (int i = (0); i < ((n)); i++) cout << v[i] << (i == n - 1 ? '\n' : ' ');
}
template <class T>
inline void printve(vector<T>& v) {
  int n = (int)v.size();
  for (int i = (0); i < ((n)); i++) cerr << v[i] << (i == n - 1 ? '\n' : ' ');
}
template <class T>
inline void printlnv(vector<T>& v) {
  int n = (int)v.size();
  for (int i = (0); i < ((n)); i++) cout << v[i] << '\n';
}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
void solve();
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << fixed << setprecision(numeric_limits<double>::max_digits10);
  solve();
  return 0;
}
void solve() {
  int n, u, v;
  cin >> n >> u >> v;
  u--;
  v--;
  vvi g(n, vi());
  int a, b;
  vi ab(n);
  for (int i = (0); i < ((n - 1)); i++) {
    cin >> a >> b;
    a--;
    b--;
    ab[a]++;
    ab[b]++;
    g[a].emplace_back(b);
    g[b].emplace_back(a);
  }
  bool ok = false;
  for (int i = (0); i < ((n)); i++) {
    if (ab[i] > 2) ok = true;
  }
  if (!ok) {
    cerr << n << "." << u << "." << v << '\n';
    printve(ab);
    abort();
  }
  vi d(n);
  function<void(int, int)> dfs = [&](int c, int p) {
    if (p != -1)
      d[c] = d[p] + 1;
    else
      d[c] = 0;
    if (p != -1 && (int)g[c].size() == 1) return;
    for (auto e : g[c]) {
      if (e == p) continue;
      dfs(e, c);
    }
  };
  dfs(v, -1);
  vi r(n);
  int ans = 0;
  bool f = true;
  function<void(int, int)> dfs2 = [&](int c, int p) {
    if (p != -1)
      r[c] = r[p] + 1;
    else
      r[c] = 0;
    if (r[c] > d[c]) {
      return;
    } else if (r[c] == d[c]) {
      chmax(ans, r[c]);
      return;
    } else if (r[c] + 1 == d[c] and f) {
      chmax(ans, r[c] * 2);
      f = false;
    }
    chmax(ans, r[c]);
    if (p != -1 && (int)g[c].size() == 1) {
      chmax(ans, d[p]);
      return;
    }
    for (auto e : g[c]) {
      if (e == p) continue;
      dfs2(e, c);
    }
  };
  dfs2(u, -1);
  cout << ans << '\n';
}
