#include <bits/stdc++.h>
using namespace std;
int n;
vector<vector<int> > tree;
void dfs(int s, int p, int l, vector<int> &f) {
  f[s] = l;
  for (int x : tree[s]) {
    if (x == p) continue;
    dfs(x, s, l + 1, f);
  }
  return;
}
int main() {
  cin >> n;
  int u, v;
  cin >> u >> v;
  u--;
  v--;
  tree.assign(n, vector<int>(0));
  for (long long i = 0; i < (long long)(n - 1); i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    tree[a].push_back(b);
    tree[b].push_back(a);
  }
  vector<int> fu(n);
  vector<int> fv(n);
  dfs(u, -1, 0, fu);
  dfs(v, -1, 0, fv);
  int maxu = 0, maxv = 0, k = u;
  for (long long i = 0; i < (long long)(n); i++) {
    if (fu[i] <= fv[i] && maxu < fv[i]) {
      maxu = fv[i];
      k = i;
    }
  }
  cout << fu[k] << endl;
  return 0;
}
