#include <bits/stdc++.h>
using namespace std;
static const int INTINF = (2147483647 >> 1);
static const long long LLINF = (9223372036854775807 >> 1);
static const int MAX = 1e5 + 1;
static const long long MOD = 1e9 + 7;
namespace Kunitaka {
template <typename TYPE, std::size_t SIZE>
std::size_t array_length(const TYPE (&array)[SIZE]) {
  return SIZE;
}
}  // namespace Kunitaka
using namespace Kunitaka;
namespace Printer {
void br() { cout << endl; }
void loop_cnt(int i) { cout << "i = " << i << endl; }
void loop_cnt(int i, int j) {
  cout << "i = " << i << ", "
       << "j = " << j << endl;
}
template <class T>
void print(T x) {
  cout << x << endl;
}
template <class T, class S>
void print(T x, S y) {
  cout << x << "," << y << endl;
}
template <class T, class S, class U>
void print(T x, S y, U z) {
  cout << x << "," << y << "," << z << endl;
}
template <class T, class S>
void print(pair<T, S> p) {
  cout << p.first << ", " << p.second << endl;
}
template <typename TYPE, std::size_t SIZE>
void print(const TYPE (&array)[SIZE]) {
  int lim = array_length(array);
  for (int i = 0; i < lim; i++) {
    if (i) cout << " ";
    cout << array[i];
  }
  cout << endl;
}
template <class S>
void print(vector<S> v) {
  for (int i = 0; i < v.size(); i++) {
    if (i) cout << " ";
    cout << v[i];
  }
  cout << endl;
}
template <class S>
void print(vector<vector<S> > vv) {
  for (int i = 0; i < vv.size(); i++) {
    for (int j = 0; j < vv[i].size(); j++) {
      if (j) cout << " ";
      cout << vv[i][j];
    }
    cout << endl;
  }
}
void yesno(bool x) {
  if (x)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
};  // namespace Printer
using namespace Printer;
vector<vector<int> > g(MAX);
vector<vector<int> > g2(MAX);
vector<int> keiro(MAX);
vector<int> keiro2;
int calc(int v, int bef, int dep, int target) {
  keiro[v] = dep;
  if (v == target) {
    return dep;
  }
  int res = 0;
  for (int u : g[v]) {
    if (bef == u) continue;
    res = max(res, calc(u, v, dep + 1, target));
  }
  return res;
}
void findRoute(int v, int bef) {
  keiro2.push_back(v);
  if (keiro[v] == 0) return;
  int mi = INTINF;
  int idx = 0;
  for (int u : g[v]) {
    if (bef == u) continue;
    if (keiro[u] < mi) {
      mi = keiro[u];
      idx = u;
    }
  }
  findRoute(idx, v);
}
int solve(int v, int bef, int dep) {
  int res = dep;
  for (int u : g2[v]) {
    if (u == bef) continue;
    res = max(res, solve(u, v, dep + 1));
  }
  return res;
}
int main(int argc, const char* argv[]) {
  cout << fixed << setprecision(10);
  int N, u, v;
  cin >> N >> u >> v;
  vector<int> as(N);
  vector<int> bs(N);
  u--;
  v--;
  for (int i = 0; i < (N - 1); ++i) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    as[i] = a;
    bs[i] = b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  int tmp = calc(v, -1, 0, u);
  findRoute(u, -1);
  int m = (tmp - 1);
  int mm = m / 2;
  int p = keiro2[mm];
  int q = keiro2[mm + 1];
  for (int i = 0; i < (N - 1); ++i) {
    int a, b;
    a = as[i];
    b = bs[i];
    if ((a == p && b == q) || (b == p && a == q)) continue;
    g2[a].push_back(b);
    g2[b].push_back(a);
  }
  int ans = solve(p, -1, 0) + mm;
  if (tmp % 2 == 0) ans++;
  print(ans);
  return 0;
}
