#include <bits/stdc++.h>
using namespace std;
int N;
vector<vector<int>> K(210000);
int t[210000];
int preT[210000];
int a[210000];
int preA[210000];
void search(int start, int cost[210000], int pre[210000]) {
  queue<int> W;
  W.push(start);
  for (int x = 0; x < (N); x++) {
    cost[x + 1] = INT_MAX / 2;
  }
  cost[start] = 0;
  pre[start] = -1;
  int j = start;
  int des = 0;
  while (!W.empty()) {
    int x = W.front();
    W.pop();
    for (int y = 0; y < (K[x].size()); y++) {
      if (cost[K[x][y]] > cost[x] + 1) {
        cost[K[x][y]] = cost[x] + 1;
        pre[K[x][y]] = x;
        W.push(K[x][y]);
      }
    }
  }
}
int main() {
  int u, v;
  cin >> N >> u >> v;
  for (int x = 0; x < (N - 1); x++) {
    int a, b;
    cin >> a >> b;
    K[a].push_back(b);
    K[b].push_back(a);
  }
  search(u, t, preT);
  search(v, a, preA);
  int ta = -1, ao;
  int maxi = 0;
  for (int x = 0; x < (N); x++) {
    if (t[x + 1] <= a[x + 1] && t[x + 1] > maxi) {
      maxi = t[x + 1];
      ta = ao = x + 1;
    }
  }
  if (ta < 0) {
    cout << 0 << endl;
    ;
    return 0;
  }
  vector<int>(T);
  ;
  vector<int>(A);
  ;
  (T).push_back((ta));
  ;
  (A).push_back((ao));
  ;
  while (preT[ta] > 0) {
    (T).push_back((preT[ta]));
    ;
    ta = preT[ta];
  }
  if (T.size() == 1) {
    (T).push_back((preA[ta]));
  }
  while (preA[ao] > 0) {
    (A).push_back((preA[ao]));
    ;
    ao = preA[ao];
  }
  int ans = 0;
  reverse((T).begin(), (T).end());
  ;
  reverse((A).begin(), (A).end());
  ;
  ta = 0;
  ao = 0;
  int i = 0;
  int orient = 1;
  while (T[ta] != A[ao]) {
    if (i % 2 == 0) {
      if (ta == T.size() - 1) {
        orient = -1;
      } else if (ta == -1) {
        orient = 1;
      }
      ta += orient;
    } else {
      ao++;
      ans++;
    }
    i++;
  }
  cout << ans << endl;
  return 0;
}
