#include <bits/stdc++.h>
using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
const long long SZ = 1e5 + 4;
const double EPS = 1e-7;
const long long mod = 1e9 + 7;
const long long inf = 1e9 + 9;
struct custom_hash {
  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM =
        chrono::steady_clock::now().time_since_epoch().count();
    return x + FIXED_RANDOM;
  }
};
long long n, x, y;
vector<long long> g[SZ];
void read() {
  cin >> n >> x >> y;
  --x, --y;
  for (long long i = 1; i < n; ++i) {
    long long u, v;
    cin >> u >> v;
    --u, --v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
}
long long tim[SZ];
bool used1[SZ];
void dfs1(long long u, long long t = 0) {
  used1[u] = true;
  tim[u] = t;
  for (long long v : g[u]) {
    if (!used1[v]) {
      dfs1(v, t + 1);
    }
  }
}
bool used[SZ];
long long ans = 1;
void dfs2(long long u, long long t = 0) {
  used[u] = true;
  ans = max(t, ans);
  for (long long v : g[u]) {
    if (t + 1 < tim[v]) {
      dfs2(v, t + 1);
    }
  }
}
void solve() {
  if (g[x].size() == 1 && g[x][0] == y) {
    cout << 0;
    return;
  }
  dfs1(y);
  dfs2(x);
  cout << ans;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  read();
  solve();
  return 0;
}
