#include <bits/stdc++.h>
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
using namespace std;
int main(void) {
  int n, u, v;
  cin >> n >> u >> v;
  u--;
  v--;
  vector<vector<int>> t(n);
  for (int i = 0; i < (int)n - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    t[a].push_back(b);
    t[b].push_back(a);
  }
  vector<int> s(n, -1), w(n, -1);
  queue<int> que;
  que.push(v);
  s[v] = 0;
  while (que.size()) {
    int x = que.front();
    que.pop();
    for (int i = 0; i < (int)t[x].size(); i++) {
      int y = t[x][i];
      if (s[y] == -1) {
        que.push(y);
        s[y] = s[x] + 1;
      }
    }
  }
  int res = 0;
  que.push(u);
  w[u] = 0;
  while (que.size()) {
    int x = que.front();
    que.pop();
    for (int i = 0; i < (int)t[x].size(); i++) {
      int y = t[x][i];
      if (w[y] == -1) {
        que.push(y);
        w[y] = w[x] + 1;
      }
    }
  }
  for (int i = 0; i < (int)n; i++) {
    if (s[i] > w[i]) {
      if (s[u] % 2 == 0 && s[u] > 2)
        chmax(res, s[i]);
      else
        chmax(res, s[i] - 1);
    }
  }
  cout << res << endl;
}
