#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
vector<vector<int>> to;
vector<int> dep;
int v, u;
int dfs(int uu, int par = -1) {
  if (dep[uu] == -1) return -1;
  int mdepth = -1;
  if (uu == v) {
    dep[uu] = -1;
    return -1;
  }
  for (auto vv : to[uu]) {
    if (vv == par) continue;
    mdepth = max(mdepth, dfs(vv, uu));
  }
  dep[uu] = mdepth + 1;
  return mdepth + 1;
}
int dfs2(int vv, int par = -1) {
  if (vv == u) return 1;
  int ans = 0;
  for (auto uu : to[vv]) {
    if (uu == par) continue;
    ans = max(ans, dfs2(uu, vv));
  }
  return ans;
}
int main() {
  int n;
  cin >> n >> u >> v;
  --u;
  --v;
  int a, b;
  long long ans = 0;
  to.resize(n);
  dep.resize(n);
  for (int i = 1; i <= n - 1; ++i) {
    cin >> a >> b;
    --a;
    --b;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  while (u != v) {
    dfs(u);
    int next = -1, nextd = -1;
    for (auto nextu : to[u]) {
      if (nextd < dep[nextu]) {
        nextd = dep[nextu];
        next = nextu;
      }
    }
    u = next;
    if (next == -1) break;
    for (auto nextv : to[v]) {
      if (dfs2(nextv) == 1) next = nextv;
    }
    v = next;
    ans++;
  }
  cout << ans << endl;
  return 0;
}
