#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using Graph = vector<vector<int>>;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const int INF = 1e9;
const LL LLINF = 1e16;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, u, v;
  cin >> n >> u >> v;
  u--;
  v--;
  Graph G(n);
  for (int i = (0); i < (n - 1); i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  if (u == v) {
    cout << 0 << endl;
    return 0;
  }
  queue<pair<int, int>> que;
  que.push(make_pair(v, 0));
  vector<int> time(n, -1);
  while (!que.empty()) {
    int m, t;
    tie(m, t) = que.front();
    que.pop();
    time[m] = t;
    for (auto&& i : G[m]) {
      if (time[i] == -1) {
        que.push(make_pair(i, t + 1));
      }
    }
  }
  que.push(make_pair(u, 0));
  int ans = 0;
  while (!que.empty()) {
    int m, t;
    tie(m, t) = que.front();
    que.pop();
    int tmp = -1;
    for (auto&& i : G[m]) {
      if (time[i] > t + 1) {
        que.push(make_pair(i, t + 1));
      } else {
        chmax(tmp, time[i]);
      }
    }
    if (tmp != -1) chmax(ans, tmp);
  }
  cout << ans << endl;
}
