#include <bits/stdc++.h>
using namespace std;
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
const int inf = 1e9;
void show(const VI &v) {
  for (int i = 0; i < v.size(); i++) {
    printf("%d: %d\n", i + 1, v[i]);
  }
}
VI make_dist(int st, const VVI &connect) {
  int n = connect.size();
  VI dist(n, inf);
  queue<int> que;
  que.push(st);
  dist[st] = 0;
  while (!que.empty()) {
    auto x = que.front();
    que.pop();
    for (auto y : connect[x]) {
      if (dist[y] == inf) {
        dist[y] = dist[x] + 1;
        que.push(y);
      }
    }
  }
  return dist;
}
int get_far(int pos, const VI &dist, const VVI &connect) {
  int to = pos;
  for (auto x : connect[pos]) {
    if (dist[x] > dist[to]) {
      to = x;
    }
  }
  return to;
}
int get_closer(int pos, const VI &dist, const VVI &connect) {
  int to = pos;
  for (auto x : connect[pos]) {
    if (dist[x] < dist[to]) {
      to = x;
    }
  }
  return to;
}
int main() {
  int n, u, v, a, b;
  cin >> n >> u >> v;
  u--;
  v--;
  VVI connect(n);
  for (int i = 0; i < n - 1; i++) {
    cin >> a >> b;
    a--;
    b--;
    connect[a].push_back(b);
    connect[b].push_back(a);
  }
  int ans = 0;
  if (u == v) {
    cout << ans << endl;
    return 0;
  }
  int pos_t = u;
  int pos_a = v;
  auto dist_t1 = make_dist(pos_t, connect);
  auto dist_a1 = make_dist(pos_a, connect);
  while (dist_a1[pos_t] - dist_a1[pos_a] > 2) {
    pos_t = get_closer(pos_t, dist_a1, connect);
    pos_a = get_far(pos_a, dist_a1, connect);
    ans++;
  }
  auto dist_a2 = make_dist(pos_a, connect);
  auto connect2 = connect;
  for (auto x : connect[pos_t]) {
    if (dist_a2[x] < dist_a2[pos_t]) {
      connect2[pos_t].clear();
      for (auto y : connect[pos_t]) {
        if (y != x) {
          connect2[pos_t].emplace_back(y);
        }
      }
      connect2[x].clear();
      for (auto y : connect[x]) {
        if (y != pos_t) {
          connect2[x].emplace_back(y);
        }
      }
      break;
    }
  }
  auto dist_t2 = make_dist(pos_t, connect2);
  int to = pos_t;
  for (int i = 0; i < n; i++) {
    if (connect[i].size() == 1 && dist_t2[i] < dist_a2[i] &&
        dist_t2[i] != inf && dist_t2[i] > dist_t2[to]) {
      to = i;
    }
  }
  ans += dist_t2[to];
  if (dist_a2[pos_t] == 2) {
    ans += 1;
  }
  cout << ans << endl;
  return 0;
}
