#include <bits/stdc++.h>
using namespace std;
vector<vector<long long>> connec(110000);
vector<long long> l1(110000, 0);
vector<long long> reached1(110000, false);
vector<long long> reached2(110000, false);
vector<long long> l2(110000, 0);
void dfs1(long long x) {
  reached1[x] = true;
  if (connec[x].size() != 0) {
    for (long long i = 0; i < (long long)(connec[x].size()); i++) {
      if (reached1.at(connec[x][i]) == false) {
        l1.at(connec[x][i]) = l1.at(x) + 1;
        dfs1(connec[x][i]);
      }
    }
  }
  return;
}
void dfs2(long long x) {
  reached2[x] = true;
  if (connec[x].size() != 0) {
    for (long long i = 0; i < (long long)(connec[x].size()); i++) {
      if (reached2.at(connec[x][i]) == false) {
        if (l1.at(connec[x][i]) == l2.at(x) + 1) {
          l2.at(connec[x][i]) = l2.at(x) + 1;
        } else {
          l2.at(connec[x][i]) = l2.at(x) + 1;
          dfs2(connec[x][i]);
        }
      }
    }
  }
  return;
}
int main() {
  long long n, u, v;
  cin >> n >> u >> v;
  for (long long i = 0; i < (long long)(n - 1); i++) {
    long long a, b;
    cin >> a >> b;
    connec[a - 1].push_back(b - 1);
    connec[b - 1].push_back(a - 1);
  }
  dfs1(v - 1);
  dfs2(u - 1);
  long long ans = 0;
  for (long long i = 0; i < (long long)(n); i++) {
    if (l1.at(i) > l2.at(i)) {
      ans = max(ans, l1.at(i) - 1);
    } else if (l1.at(i) == l2.at(i)) {
      ans = max(ans, l2.at(i));
    }
  }
  cout << ans << endl;
}
