#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
inline bool chmin(T1& a, T2 b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T1, typename T2>
inline bool chmax(T1& a, T2 b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class Type>
struct is_vector : std::false_type {};
template <class ValueType, class Alloc>
struct is_vector<std::vector<ValueType, Alloc>> : std::true_type {};
template <typename T>
inline ostream& operator<<(ostream& out, const vector<T>& v) {
  if (v.empty()) return out;
  constexpr bool is_vector_v = is_vector<T>::value;
  if (is_vector_v)
    for (auto itr = v.begin(); itr != v.end();)
      out << (*itr), out << ((++itr != v.end()) ? "\n" : "");
  else
    for (auto itr = v.begin(); itr != v.end();)
      out << (*itr), out << ((++itr != v.end()) ? " " : "");
  return out;
}
inline void put() {}
template <class T>
inline void put(const T& first) {
  std::cout << first << "\n";
}
template <class T, class... N>
inline void put(const T& first, const N&... rest) {
  std::cout << first << " ";
  put(rest...);
}
inline void putn() {}
template <class T, class... N>
inline void putn(const T& first, const N&... rest) {
  std::cout << first << "\n";
  putn(rest...);
}
int main() {
  cin.tie(0), ios::sync_with_stdio(false);
  int n, u, v;
  cin >> n >> u >> v;
  u--;
  v--;
  vector<int> a(n - 1), b(n - 1);
  vector<vector<int>> path(n);
  for (long long i = 0; i < (long long)(n - 1); i++) {
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
    path[a[i]].push_back(b[i]);
    path[b[i]].push_back(a[i]);
  }
  int res = 0;
  queue<int> qa, qb;
  vector<int> da(n, -1);
  da[v] = 0;
  qa.push(v);
  vector<int> db(n, -1);
  db[u] = 0;
  qb.push(u);
  while (!qa.empty()) {
    int pa = qa.front();
    qa.pop();
    for (long long i = 0; i < (long long)(path[pa].size()); i++) {
      if (da[path[pa][i]] < 0) {
        da[path[pa][i]] = da[pa] + 1;
        qa.push(path[pa][i]);
      }
    }
  }
  int tmp = -1;
  while (!qb.empty()) {
    int pb = qb.front();
    qb.pop();
    for (long long i = 0; i < (long long)(path[pb].size()); i++) {
      if (db[path[pb][i]] < 0) {
        db[path[pb][i]] = db[pb] + 1;
        if (db[path[pb][i]] == da[path[pb][i]]) {
          if (tmp < 0) {
            tmp = db[path[pb][i]];
          }
        }
        qb.push(path[pb][i]);
      }
    }
  }
  if (tmp >= 0) {
    put(tmp);
    return 0;
  }
  for (long long i = 0; i < (long long)(n); i++) {
    if (da[i] > db[i]) {
      chmax(res, db[i]);
    }
  }
  a.at(1000000000);
  put(res);
  return 0;
}
