#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,inline,unroll-loops,fast-math")
using namespace std;
int main(int argc, char *argv[]) {
  int n, u, v;
  cin >> n >> u >> v;
  unordered_map<int, unordered_set<int>> um;
  for (int i = 1; i < n; i++) {
    int a, b;
    cin >> a >> b;
    um[a].insert(b);
    um[b].insert(a);
  }
  unordered_map<int, int> du, dv;
  unordered_map<int, int> du_last, dv_last;
  vector<int> v1, v2;
  v1.push_back(u);
  du[u] = 0;
  while (v1.size() > 0) {
    v2.clear();
    for (auto vv : v1) {
      for (auto next : um[vv]) {
        if (du.find(next) == du.end()) {
          du[next] = du[vv] + 1;
          v2.push_back(next);
          du_last[next] = vv;
        }
      }
    }
    v1 = v2;
  }
  v1.clear();
  v1.push_back(v);
  dv[v] = 0;
  while (v1.size() > 0) {
    v2.clear();
    for (auto vv : v1) {
      for (auto next : um[vv]) {
        if (dv.find(next) == dv.end()) {
          dv[next] = dv[vv] + 1;
          v2.push_back(next);
          dv_last[next] = vv;
        }
      }
    }
    v1 = v2;
  }
  int res = 0;
  for (int i = 1; i <= n; i++) {
    if (um[i].size() == 1) {
      if (du[i] < dv[i]) {
        res = max(res, (du[i] + dv[i]) / 2);
      }
    }
  }
  cout << res << endl;
}
