#include <bits/stdc++.h>
using namespace std;
long long int inf = 1e9;
vector<long long int> daikus(
    vector<vector<pair<long long int, long long int> > > &g, int s) {
  long long int v = g.size();
  vector<long long int> res(v, inf);
  priority_queue<pair<long long int, long long int>,
                 vector<pair<long long int, long long int> >,
                 greater<pair<long long int, long long int> > >
      q;
  q.push(pair<long long int, long long int>(0, s));
  while (!q.empty()) {
    pair<long long int, long long int> now = q.top();
    q.pop();
    long long int nn = now.second;
    long long int cost = now.first;
    if (res[nn] < cost) continue;
    res[nn] = cost;
    for (int i = 0; i < g[nn].size(); i++) {
      long long int next = g[nn][i].second;
      long long int nc = cost + g[nn][i].first;
      if (res[next] < cost) continue;
      q.push(pair<long long int, long long int>(nc, next));
    }
  }
  return res;
}
int main() {
  long long int n, u, v;
  cin >> n >> u >> v;
  u--, v--;
  vector<vector<pair<long long int, long long int> > > g(n);
  for (long long int i = 0; i < n - 1; i++) {
    long long int a, b;
    cin >> a >> b;
    a--, b--;
    g[a].push_back(pair<long long int, long long int>(1, b));
    g[b].push_back(pair<long long int, long long int>(1, a));
  }
  vector<long long int> uu = daikus(g, u);
  vector<long long int> vv = daikus(g, v);
  long long int cost = 0;
  for (long long int i = 0; i < n; i++) {
    if (uu[i] < vv[i]) {
      cost = max(uu[i], cost);
    }
    if (uu[i] == vv[i]) {
      bool flag = false;
      for (int j = 0; j < g[i].size(); j++) {
        if (uu[i] > uu[g[i][j].second] &&
            uu[g[i][j].second] == vv[g[i][j].second]) {
          flag = true;
          break;
        }
      }
      if (!flag) cost = max(cost, uu[i]);
    }
  }
  cout << cost << endl;
  return 0;
}
