#include <bits/stdc++.h>
using namespace std;
long long int n, i, j, k;
int main() {
  ios_base::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
  ;
  long long int u, v, a, b;
  cin >> n >> a >> b;
  vector<vector<long long int> > adj(n + 1, vector<long long int>());
  for (i = 1; i < n; i++) {
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  vector<long long int> da(n + 1, 1e18), db(n + 1, 1e18);
  vector<bool> used(n + 1, false);
  used[a] = true;
  queue<long long int> q;
  q.push(a);
  da[a] = 0;
  while (!q.empty()) {
    u = q.front();
    q.pop();
    for (auto to : adj[u]) {
      if (!used[to]) {
        used[to] = true;
        da[to] = da[u] + 1;
        q.push(to);
      }
    }
  }
  used.assign(n + 1, false);
  used[b] = true;
  q.push(b);
  db[b] = 0;
  while (!q.empty()) {
    u = q.front();
    q.pop();
    for (auto to : adj[u]) {
      if (!used[to]) {
        used[to] = true;
        db[to] = db[u] + 1;
        q.push(to);
      }
    }
  }
  long long int max_dis = *max_element(db.begin() + 1, db.end());
  for (i = 1; i <= n; i++) {
    if (db[i] == max_dis) {
      if (max_dis > da[i]) {
        cout << max_dis - 1 << endl;
        return 0;
      }
    }
  }
  if (da[b] % 2 == 0) {
    cout << da[b] / 2 << endl;
  } else
    cout << ((da[b] / 2) + 1) << endl;
}
