#include <bits/stdc++.h>
using namespace std;
int n, u, v;
vector<vector<int>> t(100005);
int main(void) {
  cin >> n >> u >> v;
  u--;
  v--;
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    t[a].push_back(b);
    t[b].push_back(a);
  }
  queue<int> que;
  que.push(u);
  bool jud[n];
  fill(jud, jud + n, false);
  int a[n], b[n];
  a[u] = 0;
  jud[u] = true;
  while (que.size() > 0) {
    int x = que.front();
    que.pop();
    for (int i = 0; i < t[x].size(); i++) {
      int y = t[x][i];
      if (jud[y]) continue;
      que.push(y);
      jud[y] = true;
      a[y] = a[x] + 1;
    }
  }
  b[v] = 0;
  fill(jud, jud + n, false);
  que.push(v);
  jud[v] = true;
  while (que.size() > 0) {
    int x = que.front();
    que.pop();
    for (int i = 0; i < t[x].size(); i++) {
      int y = t[x][i];
      if (jud[y]) continue;
      que.push(y);
      jud[y] = true;
      b[y] = b[x] + 1;
    }
  }
  int res = 0, mini = 100005;
  for (int i = 0; i < n; i++) {
    if (a[i] == b[i]) {
      mini = min(mini, b[i]);
    } else if (b[i] > a[i]) {
      res = max(res, b[i]);
    }
  }
  if (mini != 100005) res = max(mini, res);
  if (res == 2 && a[v] == 2) {
    cout << 1 << endl;
    return 0;
  } else if (a[v] % 2 == 1) {
    res--;
  }
  cout << res << endl;
}
