#include <bits/stdc++.h>
using ll = long long;
using namespace std;
void dfs(vector<vector<int>> &tree, int now, int bf, vector<int> &ans, int o,
         vector<int> &leaf, bool mode) {
  bool flag = true;
  for (int i : tree.at(now)) {
    if (i == bf) continue;
    ans.at(i) = ans.at(now) + 1;
    flag = false;
    if (i == o) {
      leaf.push_back(i);
      continue;
    }
    dfs(tree, i, now, ans, o, leaf, mode);
  }
  if (mode == true && flag == true) leaf.push_back(now);
}
int main() {
  int n, u, v;
  cin >> n >> u >> v;
  u--;
  v--;
  vector<vector<int>> tree(n, vector<int>());
  for (int i = 0; i < (int)(n - 1); i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    tree.at(a).push_back(b);
    tree.at(b).push_back(a);
  }
  vector<int> u_d(n, -1), v_d(n, -1), leaf;
  u_d.at(u) = 0;
  dfs(tree, u, -1, u_d, v, leaf, false);
  v_d.at(v) = 0;
  dfs(tree, v, -1, v_d, u, leaf, true);
  int ans = 0;
  for (int i : leaf) {
    if (u_d.at(i) < v_d.at(i)) {
      ans = max(ans, v_d.at(i));
    }
  }
  cout << ans - 1 << endl;
  return 0;
}
