#include <bits/stdc++.h>
using namespace std;
const int inf = 1 << 30;
const long long linf = 1LL << 62;
long long dy[8] = {1, 0, -1, 0, 1, -1, 1, -1};
long long dx[8] = {0, 1, 0, -1, 1, -1, -1, 1};
const double pi = acos(-1);
template <typename T1, typename T2>
inline void chmin(T1 &a, T2 b) {
  if (a > b) a = b;
}
template <typename T1, typename T2>
inline void chmax(T1 &a, T2 b) {
  if (a < b) a = b;
}
template <typename T1, typename T2>
inline void print2(T1 a, T2 b) {
  cout << a << " " << b << endl;
}
template <typename T1, typename T2, typename T3>
inline void print3(T1 a, T2 b, T3 c) {
  cout << a << " " << b << " " << c << endl;
}
const int MAX = 1020000;
const double EPS = 1e-6;
const int mod = 1e9 + 7;
int main() {
  long long n, u, v;
  cin >> n >> u >> v;
  u--;
  v--;
  vector<vector<long long> > G(n);
  for (long long i = 0; i < (n - 1); i++) {
    long long a, b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  queue<long long> q;
  vector<long long> d(n, inf);
  d[u] = 0;
  q.push(u);
  vector<long long> pre(n, -1);
  while (!q.empty()) {
    long long s = q.front();
    q.pop();
    for (auto t : G[s]) {
      if (d[t] == inf) {
        d[t] = d[s] + 1;
        q.push(t);
      }
    }
  }
  q.push(v);
  vector<long long> e(n, inf);
  e[v] = 0;
  while (!q.empty()) {
    long long s = q.front();
    q.pop();
    for (auto t : G[s]) {
      if (e[t] == inf) {
        e[t] = e[s] + 1;
        q.push(t);
      }
    }
  }
  long long mx = 0;
  for (long long i = 0; i < (n); i++) {
    if (i == u) continue;
    if (d[i] < e[i]) {
      chmax(mx, e[i] - 1);
    } else if (d[i] == e[i]) {
      chmax(mx, 1LL);
    }
  }
  cout << mx << endl;
}
