#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvb = vector<vb>;
constexpr int MOD = 1000000007;
void bfs(const vvi& G, vi& d, int root) {
  int n = G.size();
  queue<int> q;
  vb seen(n, false);
  q.push(root);
  seen[root] = true;
  d[root] = 0;
  while (!q.empty()) {
    int curr = q.front();
    q.pop();
    for (int next : G[curr]) {
      if (seen[next]) {
        continue;
      }
      q.push(next);
      seen[next] = true;
      d[next] = d[curr] + 1;
    }
  }
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, u, v;
  cin >> n >> u >> v;
  --u;
  --v;
  vvi G(n);
  for (int i = 0; i < (int)(n - 1); ++i) {
    int a, b;
    cin >> a >> b;
    G[a - 1].push_back(b - 1);
    G[b - 1].push_back(a - 1);
  }
  vi from_u(n, -1), from_v(n, -1);
  bfs(G, from_u, u);
  bfs(G, from_v, v);
  int dist = from_u[v];
  if (dist <= 1) {
    cout << 0 << endl;
    return 0;
  }
  int ans = 0;
  for (int i = 0; i < (int)(n); ++i) {
    if (from_u[i] + from_v[i] == dist) {
      ans = max(ans, dist - 1);
      continue;
    }
    int d = abs(from_u[i] - from_v[i]);
    if (d < dist) {
      if (from_u[i] < from_v[i]) {
        int tmp = from_u[i] + d - 1;
        ans = max(ans, tmp);
      }
      continue;
    }
    if (from_u[i] > from_v[i]) {
      int tmp = from_u[i] + dist - 1;
      ans = max(ans, tmp);
    }
  }
  cout << ans << endl;
  return 0;
}
