#include <bits/stdc++.h>
using namespace std;
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (T &x : vec) is >> x;
  return is;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &pair_var) {
  os << "(" << pair_var.first << ", " << pair_var.second << ")";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "{";
  for (int i = 0; i < (int)vec.size(); i++)
    os << vec[i] << (i + 1 == (int)vec.size() ? "" : ", ");
  os << "}";
  return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, map<T, U> &map_var) {
  os << "{";
  for (auto &&itr : map_var) {
    os << *itr;
    itr++;
    if (itr != map_var.end()) os << ", ";
    itr--;
  }
  os << "}";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, set<T> &set_var) {
  os << "{";
  for (auto &&itr : set_var) {
    os << *itr;
    itr++;
    if (itr != set_var.end()) os << ", ";
    itr--;
  }
  os << "}";
  return os;
}
void dump_func() { cerr << endl; }
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&...tail) {
  cerr << head;
  if (sizeof...(Tail) > 0) cerr << ", ";
  dump_func(std::move(tail)...);
}
using namespace std;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
using vec = std::vector<T>;
template <class T>
void print(const T &x) {
  cout << x << "\n";
}
const long long MOD = 1000000007, INF0 = 1061109567, INF = INF0 * INF0;
const double EPS = 1e-10, PI = acos(-1.0);
const long long dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
vec<long long> G[200200];
long long d[200200];
long long d2[200200];
bool flg[200200];
long long d3[200200];
void dfs(long long id, long long cost, long long parent, long long di[200200]) {
  di[id] = cost;
  for (auto &&e : G[id]) {
    if (e != parent) {
      dfs(e, cost + 1, id, di);
    }
  }
}
void dfs2(long long id, long long cost, long long parent,
          long long di[200200]) {
  di[id] = cost;
  for (auto &&e : G[id]) {
    if (e != parent && flg[e]) {
      dfs2(e, cost + 1, id, di);
    }
  }
}
signed main() {
  cin.tie(0), ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);
  long long N, u, v;
  cin >> N >> u >> v;
  u--, v--;
  for (long long i = 0; i < N - 1; i++) {
    long long p, q;
    cin >> p >> q;
    p--, q--;
    G[p].push_back(q);
    G[q].push_back(p);
  }
  fill(d, d + N, INF);
  dfs(u, 0, -1, d);
  dfs(v, 0, -1, d2);
  long long ans = 0;
  for (long long i = 0; i < N; i++) {
    if (d[i] < d2[i]) {
      flg[i] = true;
    } else {
      long long diff = d[i] - d2[i];
      long long tmp;
      if (diff != 2 && diff % 2 == 0)
        tmp = 0;
      else
        tmp = -1;
      chmax(ans, d2[i] + tmp);
      ;
      ans = 0;
    }
  }
  fill(d3, d3 + N, -1);
  dfs2(u, 0, -1, d3);
  ;
  ;
  for (long long i = 0; i < N; i++) {
    if (d3[i] <= d2[i]) {
      long long diff = d2[i] - d3[i];
      long long tmp;
      if (diff != 2 && diff % 2 == 0)
        tmp = 0;
      else
        tmp = -1;
      tmp = -1;
      chmax(ans, d2[i] + tmp);
      ;
    }
  }
  print(ans);
}
