#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) {
  for (int i : tree.at(now)) {
    if (i == bf) continue;
    ans.at(i) = ans.at(now) + 1;
    if (i == o) continue;
    dfs(tree, i, now, ans, o);
  }
}
void dfs2(vector<vector<int>> &tree, vector<int> &u_d, vector<int> &v_d,
          int now, int bf) {
  for (int i : tree.at(now)) {
    if (i == bf) continue;
    if (v_d.at(i) != u_d.at(i)) continue;
    v_d.at(i) = u_d.at(i) = -2;
    dfs2(tree, u_d, v_d, i, 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);
  u_d.at(u) = 0;
  dfs(tree, u, -1, u_d, v);
  v_d.at(v) = 0;
  dfs(tree, v, -1, v_d, u);
  int mxd = 0;
  for (int i = 0; i < (int)(n); i++) {
    if (u_d.at(i) > v_d.at(i) || (u_d.at(i) == -2 && v_d.at(i) == -2)) continue;
    if (u_d.at(i) == v_d.at(i)) {
      dfs2(tree, v_d, u_d, i, -1);
    }
    if (mxd > v_d.at(i)) continue;
    if (mxd < v_d.at(i)) {
      mxd = v_d.at(i);
    }
  }
  cout << mxd - 1 << endl;
  return 0;
}
