#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, u, v;
  cin >> n >> u >> v;
  u--;
  v--;
  vector<vector<pair<int, int>>> g(n, vector<pair<int, int>>());
  for (int i = 0; i < (n - 1); i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back({1, b});
    g[b].push_back({1, a});
  }
  if (g[u].size() == 1 && g[u][0].second == v) {
    cout << 0 << endl;
    return 0;
  }
  set<int> s;
  vector<int> d(n);
  for (int i = 0; i < (n); i++) d[i] = 10000000;
  d[u] = 0;
  priority_queue<pair<int, int>, vector<pair<int, int>>,
                 greater<pair<int, int>>>
      pq;
  pq.push({0, u});
  while (pq.size()) {
    auto cn = pq.top();
    pq.pop();
    if (d[cn.second] < cn.first) continue;
    for (auto nn : g[cn.second]) {
      if (cn.first + 1 >= d[nn.second] || nn.second == v) continue;
      d[nn.second] = cn.first + 1;
      pq.push({d[nn.second], nn.second});
    }
  }
  for (int i = 0; i < (n); i++)
    if (d[i] != 10000000) s.insert(i);
  s.insert(v);
  vector<int> d2(d);
  for (int i = 0; i < (n); i++) d[i] = 10000000;
  d[v] = 0;
  pq.push({0, v});
  while (pq.size()) {
    auto cn = pq.top();
    pq.pop();
    if (d[cn.second] < cn.first) continue;
    for (auto nn : g[cn.second]) {
      if (cn.first + 1 >= d[nn.second] || s.count(nn.second) == 0) continue;
      d[nn.second] = cn.first + 1;
      pq.push({d[nn.second], nn.second});
    }
  }
  int result = 0;
  bool f = true;
  for (int i = 0; i < (n); i++)
    if ((d[i] == 1 || d2[i] == 1) && d[i] != d2[i]) f = false;
  if (f) {
    cout << 1 << endl;
    return 0;
  }
  for (int i = 0; i < (n); i++)
    if (d[i] != 10000000 && d2[i] != 10000000) {
      if (d[i] <= d2[i]) continue;
      int t = d[i];
      if ((d[i] - d2[i]) % 2) t--;
      result = max(result, t);
    }
  cout << result << endl;
  return 0;
}
