#include <bits/stdc++.h>
using namespace std;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
using ll = long long;
using graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1 << 30;
const ll mod = 1000000007LL;
void dfs(const graph &g, int s, int from, vector<int> &d) {
  for (auto nx : g[s]) {
    if (nx == from) continue;
    d[nx] = d[s] + 1;
    dfs(g, nx, s, d);
  }
}
int main() {
  int N, A, B;
  cin >> N >> A >> B;
  A--;
  B--;
  vector<vector<int>> g(N);
  for (int i = 0; i < N - 1; i++) {
    int x, y;
    cin >> x >> y;
    g[x - 1].push_back(y - 1);
    g[y - 1].push_back(x - 1);
  }
  vector<int> dA(N, 0), dB(N, 0);
  dfs(g, A, -1, dA);
  dfs(g, B, -1, dB);
  int t = dA[B];
  int ans = 0;
  for (int i = 0; i < N; i++) {
    int cnt = 0;
    if (dA[i] == dB[i] + t) {
      if (t % 2 == 0) cnt = dB[i] - 1;
      if (t % 2 == 1) cnt = dB[i] - 1;
    }
    if (dA[i] + t == dB[i])
      continue;
    else {
      if (dA[i] > dB[i]) continue;
      if (dA[i] == dB[i])
        cnt = t / 2;
      else {
        if (t % 2 == 0)
          cnt = dB[i] - 1;
        else
          cnt = dB[i] - 1;
      }
    }
    chmax(ans, cnt);
  }
  cout << ans << endl;
}
