#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
int main(void) {
  int n, u, v;
  cin >> n >> u >> v;
  int a[n + 1];
  int b[n + 1];
  int f[n + 1];
  bool q[n + 1];
  bool hata[n + 1];
  vector<int> vec[n + 1];
  for (int i = 1; i <= (n - 1); i++) {
    cin >> a[i] >> b[i];
    vec[a[i]].push_back(b[i]);
    vec[b[i]].push_back(a[i]);
  }
  queue<int> vs;
  vs.push(v);
  q[v] = 1;
  int tmp;
  int cost = 0;
  int wami = 0;
  while (vs.size() != 0) {
    tmp = vs.size();
    for (int i = 0; i < tmp; ++i) {
      wami = vs.front();
      vs.pop();
      q[wami] = 0;
      f[wami] = cost;
      hata[wami] = 1;
      for (int j = 0; j < vec[wami].size(); ++j) {
        if (hata[vec[wami][j]] == 0 && q[vec[wami][j]] == 0) {
          vs.push(vec[wami][j]);
          q[vec[wami][j]] = 1;
          hata[vec[wami][j]] = 1;
        }
      }
    }
    cost++;
  }
  cost = 0;
  int f2[n + 1];
  bool q2[n + 1];
  bool hata2[n + 1];
  bool cango[n + 1];
  vs.push(u);
  q[u] = 1;
  while (vs.size() != 0) {
    tmp = vs.size();
    for (int i = 0; i < tmp; ++i) {
      wami = vs.front();
      vs.pop();
      q2[wami] = 0;
      f2[wami] = cost;
      if (f2[wami] < f[wami]) {
        cango[wami] = 1;
        for (int j = 0; j < vec[wami].size(); ++j) {
          if (hata2[vec[wami][j]] == 0 && q2[vec[wami][j]] == 0) {
            vs.push(vec[wami][j]);
            q2[vec[wami][j]] = 1;
            hata2[vec[wami][j]] = 1;
          }
        }
      }
    }
    cost++;
  }
  int ans = 0;
  for (int i = 1; i <= (n); i++) {
    if (ans < f[i] && cango[i] == 1) {
      ans = f[i];
    }
  }
  cout << ans - 1 << endl;
  return 0;
}
