#include <bits/stdc++.h>
using namespace std;
vector<long long> G[100005];
vector<long long> li;
long long n, u, v;
bool find(long long x, long long px) {
  if (x == u) {
    li.push_back(x);
    return true;
  }
  for (long long nx : G[x]) {
    if (nx == px) continue;
    if (find(nx, x)) {
      li.push_back(x);
      return true;
    }
  }
  return false;
}
long long X, maxlen;
void dfs(long long x, long long px, long long len) {
  maxlen = max(maxlen, len);
  for (long long nx : G[x]) {
    if (nx == px) continue;
    if (nx == X) continue;
    dfs(nx, x, len + 1);
  }
}
signed main() {
  cin >> n >> u >> v;
  u--, v--;
  for (long long i = 0; i < n - 1; i++) {
    long long a, b;
    cin >> a >> b;
    a--, b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  find(v, -1);
  long long s = (long long)li.size() / 2 - 1;
  X = li[s + 1];
  dfs(li[s], -1, 0);
  long long cntu = s + maxlen;
  long long cntv = (long long)li.size() - (s + 1) + maxlen;
  if (cntu == 0) {
    cout << cntv - 1 << endl;
  } else {
    cout << cntu << endl;
  }
  return 0;
}
