#include <bits/stdc++.h>
using namespace std;
int N, u, v, a, b, dep[100000] = {0}, maxL = 0;
vector<int> vec[100000];
vector<int> use[100000];
bool deep(int s, int num) {
  bool exist = false;
  if (dep[s] == 0) {
    if (u == s) return true;
    dep[s] = num;
    maxL = max(maxL, num);
    for (int i = 0; i < vec[s].size(); i++) {
      use[s][i] = deep(vec[s][i], num + 1);
      exist |= use[s][i];
    }
    return exist;
  }
  return false;
}
void deepAns(int s, int num) {
  if (dep[s] == 0) {
    dep[s] = num;
    maxL = max(maxL, num);
    for (int i = 0; i < vec[s].size(); i++) {
      if (use[s][i]) deepAns(vec[s][i], num + 1);
    }
  }
}
int main() {
  bool vast;
  cin >> N >> u >> v;
  u -= 1;
  v -= 1;
  for (int i = 0; i < N - 1; i++) {
    cin >> a >> b;
    a--;
    b--;
    vec[a].push_back(b);
    vec[b].push_back(a);
    use[a].push_back(true);
    use[b].push_back(true);
  }
  vast = deep(v, 1);
  for (int i = 0; i < N; i++) dep[i] = 0;
  maxL = 0;
  deepAns(v, 1);
  if (maxL - 1 != 0) maxL--;
  cout << maxL - 1;
  return 0;
}
