#include <bits/stdc++.h>
using namespace std;
const long long dx[] = {1, 0, -1, 0, 1, 1, -1, -1},
                dy[] = {0, -1, 0, 1, 1, -1, 1, -1};
const long long MOD = 1e9 + 7;
template <typename T>
inline T GCD(T a, T b) {
  T c;
  while (b != 0) {
    c = a % b;
    a = b;
    b = c;
  }
  return a;
}
template <typename T>
inline T LCM(T a, T b) {
  T c = GCD(a, b);
  a /= c;
  return a * b;
}
template <typename T>
inline T nCr(T a, T b) {
  T i, r = 1;
  for (i = 1; i <= b; i++) {
    r *= (a + 1 - i);
    r /= i;
  }
  return r;
}
template <typename T>
inline T nHr(T a, T b) {
  return nCr(a + b - 1, b);
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
struct edge2 {
  long long to, cost;
};
struct edge3 {
  long long from, to, cost;
};
long long N, u, v;
vector<long long> distT, distA;
vector<vector<long long> > E;
void dfs1(long long pos) {
  for (auto nxt : E[pos]) {
    if (distT[nxt] != 2000000000 or nxt == v) continue;
    distT[nxt] = distT[pos] + 1;
    dfs1(nxt);
  }
}
void dfs2(long long pos) {
  for (auto nxt : E[pos]) {
    if (distA[nxt] != 2000000000 or nxt == u) continue;
    distA[nxt] = distA[pos] + 1;
    dfs2(nxt);
  }
}
signed main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> N >> u >> v;
  distT.resize(N, 2000000000);
  distA.resize(N, 2000000000);
  u--;
  v--;
  distT[u] = 0;
  distA[v] = 0;
  E.resize(N);
  for (long long i = 0; i < (N - 1); ++i) {
    long long a, b;
    cin >> a >> b;
    a--;
    b--;
    E[a].emplace_back(b);
    E[b].emplace_back(a);
  }
  dfs1(u);
  dfs2(v);
  bool muri = 1;
  long long mx = 0, mn = 2000000000;
  for (long long i = 0; i < (N); ++i) {
    if (distT[i] > 0 and distT[i] < 2000000000) muri &= 0;
    if (distT[i] == 2000000000 or distA[i] == 2000000000) continue;
    if (distT[i] == distA[i]) {
      chmin(mn, distT[i]);
    }
    if (distT[i] < distA[i]) {
      chmax(mx, distA[i] - 1);
    }
  }
  if (mn == 2000000000) mn = -2000000000;
  if (muri)
    cout << 0 << '\n';
  else
    cout << max(mx, mn) << '\n';
}
