#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
template <class T>
ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}
const long long MOD = 1000000007;
vector<int> dis(int v, int n, map<int, vector<int>> &m) {
  queue<int> q;
  q.push(v);
  vector<int> level(n, -1);
  level[v - 1] = 0;
  while (!q.empty()) {
    int now = q.front();
    q.pop();
    for (auto next : m[now]) {
      if (level[next - 1] != -1) continue;
      q.push(next);
      level[next - 1] = level[now - 1] + 1;
    }
  }
  return level;
}
int main() {
  int n, u, v;
  cin >> n >> u >> v;
  map<int, vector<int>> m;
  for (int i = 0; i + 1 < n; i++) {
    int a, b;
    cin >> a >> b;
    if (m.find(a) == m.end()) {
      m[a] = vector<int>();
      m[a].push_back(b);
      m[b] = vector<int>();
      m[b].push_back(a);
    } else {
      m[a].push_back(b);
      m[b].push_back(a);
    }
  }
  vector<int> fromv = dis(v, n, m);
  vector<int> fromu = dis(u, n, m);
  int ans = 0;
  for (int i = 0; i < (n); ++i) {
    if (fromv[i] > fromu[i]) ans = max(ans, fromv[i] - 1);
  }
  std::cout << ans << std::endl;
  return 0;
}
