#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, u, v;
  cin >> n >> u >> v;
  --u, --v;
  vector<vector<int> > a(n);
  for (int i = 0; i < (int)(n - 1); i++) {
    int s, t;
    cin >> s >> t;
    --s, --t;
    a[s].push_back(t);
    a[t].push_back(s);
  }
  vector<int> d(n, -1);
  vector<int> p(n, -1);
  queue<int> q;
  q.push(v);
  d[v] = 0;
  while (!q.empty()) {
    int s = q.front();
    q.pop();
    for (auto t : a[s])
      if (d[t] == -1) {
        d[t] = d[s] + 1;
        p[t] = s;
        q.push(t);
      }
  }
  vector<int> l;
  int s = u;
  while (s != v) {
    l.push_back(s);
    s = p[s];
  }
  int r = (d[u] - 1) / 2;
  v = l[d[u] - r];
  u = l[r];
  int f = d[u] - 2 * r;
  q.push(u);
  vector<int> d2(n, -1);
  d2[p[u]] = -2;
  d2[u] = 0;
  int md = 0;
  while (!q.empty()) {
    int s = q.front();
    q.pop();
    for (auto t : a[s])
      if (d2[t] == -1) {
        d2[t] = d2[s] + 1;
        md = max(md, d2[t]);
        q.push(t);
      }
  }
  cout << r + f / 2 + md << endl;
  return 0;
}
