#include <bits/stdc++.h>
using namespace std;
inline long long mod(long long a, long long m) { return (a % m + m) % m; }
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int n, a[101010], b[101010], x, y;
vector<int> v[101010];
int used[101010];
void solve() {
  cin >> n >> x >> y;
  for (int i = 0; i < n - 1; i++) {
    cin >> a[i] >> b[i];
    v[a[i]].push_back(b[i]);
    v[b[i]].push_back(a[i]);
  }
  queue<pair<long long, long long> > q;
  q.push(pair<long long, long long>(y, 0));
  fill(used, used + 101010, 1000000007);
  used[y] = 0;
  while (!q.empty()) {
    pair<long long, long long> p = q.front();
    q.pop();
    int pos = p.first, now = p.second;
    for (int i = 0; i < v[pos].size(); i++) {
      int I = v[pos][i];
      if (used[I] != 1000000007) continue;
      used[I] = now + 1;
      q.push(pair<long long, long long>(I, now + 1));
    }
  }
  q.push(pair<long long, long long>(x, 0));
  int ma = 0;
  while (!q.empty()) {
    pair<long long, long long> p = q.front();
    q.pop();
    int pos = p.first, now = p.second;
    chmax(ma, now);
    if (now == used[pos]) continue;
    for (int i = 0; i < v[pos].size(); i++) {
      int I = v[pos][i];
      if (used[I] <= now) continue;
      q.push(pair<long long, long long>(I, now + 1));
    }
  }
  cout << ma << endl;
}
int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
