#include <bits/stdc++.h>
using namespace std;
int N, u, v;
void DFS(int p, int d, int s, vector<vector<int>> &m, vector<int> &dist) {
  dist[p] = d;
  for (int i : m[p]) {
    if (i == s) {
      continue;
    }
    DFS(i, d + 1, p, m, dist);
  }
}
vector<int> calculate(int p, vector<vector<int>> &m) {
  int d = 0, s = -1;
  vector<int> dist(N);
  DFS(p, d, s, m, dist);
  return dist;
}
int main() {
  int ans = 0;
  cin >> N >> u >> v;
  vector<vector<int>> m(N, vector<int>(0));
  vector<int> ud(N), vd(N);
  for (int i = 0; i < N - 1; i++) {
    int a, b;
    cin >> a >> b;
    m.at(a - 1).push_back(b - 1);
    m.at(b - 1).push_back(a - 1);
  }
  ud = calculate(u, m);
  vd = calculate(v, m);
  for (int i = 0; i < ud.size(); i++) {
    if (ud.at(i) > vd.at(i)) {
      ans = max(ans, ud.at(i));
    }
  }
  cout << ans - 1 << endl;
}
