#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const int64_t infi = 1147483600;
const long long infl = 4e18 + 5;
const char EOL = '\n';
const long long MOD = 998244353;
int main() {
  long long n, u, v;
  cin >> n >> u >> v;
  --u;
  --v;
  vector<long long> us(n, -1), vs(n, -1);
  vector<vector<long long>> e(n);
  for (long long i = 0; i < n - 1; ++i) {
    long long a, b;
    cin >> a >> b;
    --a;
    --b;
    e[a].emplace_back(b);
    e[b].emplace_back(a);
  }
  us[u] = 0;
  unordered_set<long long> qu;
  qu.insert(u);
  while (!qu.empty()) {
    auto p = *(qu.begin());
    qu.erase(p);
    for (auto iter = e[p].begin(); iter != e[p].end(); ++iter) {
      if (us[*iter] == -1) {
        us[*iter] = us[p] + 1;
        qu.insert(*iter);
      }
    }
  }
  vs[v] = 0;
  unordered_set<long long> qv;
  qv.insert(v);
  while (!qv.empty()) {
    auto p = *(qv.begin());
    qv.erase(p);
    for (auto iter = e[p].begin(); iter != e[p].end(); ++iter) {
      if (vs[*iter] == -1) {
        vs[*iter] = vs[p] + 1;
        qv.insert(*iter);
      }
    }
  }
  cerr << "us: ";
  for (long long i = 0; i < n; ++i) {
    cerr << us[i] << " ";
  }
  cerr << endl;
  cerr << "vs: ";
  for (long long i = 0; i < n; ++i) {
    cerr << vs[i] << " ";
  }
  cerr << endl;
  long long m = 0;
  for (long long i = 0; i < n; ++i) {
    if (us[i] <= vs[i]) {
      long long tmp = vs[i];
      if ((vs[i] + us[i]) % 2 == 0) {
        --tmp;
      }
      m = max(m, tmp);
    }
  }
  cout << m << endl;
}
