#include <bits/stdc++.h>
using namespace std;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int long long MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);
template <class T>
T gcd(T a, T b) {
  return b ? gcd(b, a % b) : a;
}
template <class T>
T lcm(T a, T b) {
  return a / gcd(a, b) * b;
}
int n, u, v;
vector<int> tree[100001];
int ne;
int dfsl(int t, int pare, int sum) {
  int l = 0;
  if (t == v) return -1;
  if (tree[t].size() == 1 && tree[t][0] == pare) {
    return sum;
  }
  if (tree[t].size() == -1 && tree[t][0] == v) {
    return -1;
  }
  sum++;
  for (int i = 0; i < tree[t].size(); i++) {
    if (tree[t][i] == v) continue;
    if (tree[t][i] != pare) {
      l = max(l, dfsl(tree[t][i], t, sum));
    }
  }
  return l;
}
int bds(int t) {
  queue<int> tt;
  tt.push(t);
  vector<bool> all(100001, false);
  int lo = 0;
  if (t == ne) return 0;
  while (true) {
    lo++;
    bool f = false;
    int qq = tt.front();
    tt.pop();
    all[qq] = true;
    for (int i = 0; i < tree[qq].size(); i++) {
      if (tree[qq][i] == ne) {
        f = true;
        break;
      }
      if (!all[tree[qq][i]]) {
        all[tree[qq][i]] = true;
        tt.push(tree[qq][i]);
      }
    }
    if (f) break;
  }
  return lo;
}
int main() {
  cin >> n >> u >> v;
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    tree[a].push_back(b);
    tree[b].push_back(a);
  }
  vector<int> al(100001, 0);
  queue<int> vq;
  queue<int> uq;
  vq.push(v);
  uq.push(u);
  while (true) {
    bool f = false;
    int kai = vq.size();
    for (int i = 0; i < kai; i++) {
      int s = vq.front();
      vq.pop();
      for (int j = 0; j < tree[s].size(); j++) {
        int tj = tree[s][j];
        if (al[tj] == 0) {
          al[tj] = 1;
          vq.push(tj);
        } else if (al[tj] == 2) {
          ne = tj;
          f = true;
          break;
        }
      }
      if (f) break;
    }
    if (f) break;
    kai = uq.size();
    for (int i = 0; i < kai; i++) {
      int s = uq.front();
      uq.pop();
      for (int j = 0; j < tree[s].size(); j++) {
        int tj = tree[s][j];
        if (al[tj] == 0) {
          al[tj] = 2;
          uq.push(tj);
        } else if (al[tj] == 1) {
          ne = tj;
          f = true;
          break;
        }
      }
      if (f) break;
    }
    if (f) break;
  }
  int vlong = bds(v);
  int ulong = bds(u);
  if (ulong == vlong) {
    cout << ulong << endl;
  } else if (ulong < vlong) {
    int longl = dfsl(ne, -1, 0);
    int ans = ulong + longl;
    ans += (vlong - ulong - 1);
    cout << ans << endl;
  } else {
    int suml = ulong + vlong;
    cout << suml - 1;
  }
  return 0;
}
