#include <bits/stdc++.h>
using namespace std;
long long N, u, v;
vector<long long> tree[100005];
long long memo_a[100005];
int main() {
  cin >> N >> u >> v;
  u--;
  v--;
  for (long long i = 0; i < (N - 1); ++i) {
    long long a, b;
    cin >> a >> b;
    a--;
    b--;
    tree[a].push_back(b);
    tree[b].push_back(a);
  }
  queue<pair<long long, pair<long long, long long> > > Q;
  Q.push(make_pair(v, make_pair(-1, 0)));
  while (!Q.empty()) {
    long long cur = Q.front().first;
    long long pa = Q.front().second.first;
    long long dis = Q.front().second.second;
    memo_a[cur] = dis;
    Q.pop();
    for (auto next : tree[cur]) {
      if (next != pa) {
        Q.push(make_pair(next, make_pair(cur, dis + 1)));
      }
    }
  }
  long long ans = 0;
  Q.push(make_pair(u, make_pair(-1, 0)));
  while (!Q.empty()) {
    long long cur = Q.front().first;
    long long pa = Q.front().second.first;
    long long dis = Q.front().second.second;
    Q.pop();
    if (memo_a[cur] <= dis) {
      if (tree[cur].size() == 1) {
        ans = max(ans, memo_a[tree[cur][0]]);
      }
      continue;
    }
    for (auto next : tree[cur]) {
      if (next != pa) {
        Q.push(make_pair(next, make_pair(cur, dis + 1)));
      }
    }
    if (tree[cur].size() == 1) {
      ans = max(ans, memo_a[tree[cur][0]]);
    }
  }
  cout << ans << endl;
}
