#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
const int INF = 1e9;
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, u, v;
  cin >> n >> u >> v;
  u--, v--;
  vector<vector<int>> to(n);
  for (int i = 0; i < (n - 1); i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  vector<int> dist1(n, INF), dist2(n, INF);
  dist1[u] = 0;
  queue<int> que;
  que.push(u);
  while (!que.empty()) {
    int now = que.front();
    que.pop();
    for (auto next : to[now]) {
      if (chmin(dist1[next], dist1[now] + 1)) que.push(next);
    }
  }
  dist2[v] = 0;
  que.push(v);
  while (!que.empty()) {
    int now = que.front();
    que.pop();
    for (auto next : to[now]) {
      if (chmin(dist2[next], dist2[now] + 1)) que.push(next);
    }
  }
  vector<int> node(n, -1);
  node[u] = 0;
  que.push(u);
  while (!que.empty()) {
    int now = que.front();
    que.pop();
    for (auto next : to[now]) {
      if (dist1[next] >= dist2[next] || node[next] >= 0) continue;
      node[next] = node[now] + 1;
      que.push(next);
    }
  }
  int mx = -1, idx = u;
  for (int i = 0; i < (n); i++) {
    if (chmax(mx, node[i])) idx = i;
  }
  int add = 0;
  if (dist2[idx] - dist1[idx] >= 2)
    add += max(dist2[idx] - dist1[idx] - 2, 0) * 2 + 1;
  cout << mx + add << endl;
  return 0;
}
