#include <bits/stdc++.h>
using namespace std;
vector<int> arr;
stack<int> st;
queue<int> qu;
queue<pair<int, int> > qu2;
priority_queue<int> pq;
static const int NIL = -1;
static const int INF = 1000000007;
deque<int> deq;
long long N, M, H, W, K, Q, A, B;
string S;
const long long MOD = (1e+9) + 7;
bool chmx(int &a, int b) {
  if (b > a) {
    a = b;
    return true;
  }
  return false;
}
bool chmn(int &a, int b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}
int a[10005], b[10005];
vector<int> to[10005];
int distu[10005];
int distv[10005];
int main() {
  int n, u, v;
  cin >> n >> u >> v;
  u--;
  v--;
  for (int i = 0; i < (int)(10000); i++) {
    distu[i] = -1;
    distv[i] = -1;
  }
  for (int i = 0; i < (int)(n - 1); i++) {
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
    to[a[i]].push_back(b[i]);
    to[b[i]].push_back(a[i]);
  }
  distu[u] = 0;
  qu.push(u);
  while (!qu.empty()) {
    int k = qu.front();
    qu.pop();
    for (int p : to[k]) {
      if (distu[p] == -1) {
        distu[p] = distu[k] + 1;
        qu.push(p);
      }
    }
  }
  distv[v] = 0;
  qu.push(v);
  while (!qu.empty()) {
    int k = qu.front();
    qu.pop();
    for (int p : to[k]) {
      if (distv[p] == -1) {
        distv[p] = distv[k] + 1;
        qu.push(p);
      }
    }
  }
  int ans = 0;
  cerr << endl;
  for (int i = 0; i < (int)(n); i++) {
    if (distu[i] != -1 && distu[i] < distv[i]) {
      chmx(ans, distv[i] - 1);
    }
  }
  for (int i = 0; i < (int)(n); i++) {
    cerr << distu[i] << ' ' << distv[i] << endl;
  }
  cout << ans << endl;
  return 0;
}
