#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Pi_i = pair<int, int>;
using VB = vector<bool>;
using VC = vector<char>;
using VD = vector<double>;
using VI = vector<int>;
using VLL = vector<ll>;
using VS = vector<string>;
using VSH = vector<short>;
const int MOD = 1000000007;
const int INF = 1000000000;
const int NIL = -1;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}
int V;
VI d;
vector<VI> G;
VI par;
vector<Pi_i> leaf;
int commonAncestor(int u, int v) {
  if (u == v) return u;
  if (d[u] > d[v]) return commonAncestor(par[u], v);
  return commonAncestor(u, par[v]);
}
int distant(int u, int v) { return d[u] + d[v] - 2 * d[commonAncestor(u, v)]; }
int main() {
  int u, v;
  cin >> V >> u >> v;
  --u;
  --v;
  d.resize(V, -1);
  par.resize(V, -1);
  G.resize(V);
  d[v] = 0;
  par[v] = NIL;
  for (int i = (0), i_len = (V - 1); i < i_len; ++i) {
    int a, b;
    cin >> a >> b;
    --a;
    --b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  queue<int> q;
  q.push(v);
  while (!q.empty()) {
    int cur = q.front();
    q.pop();
    int dist = d[cur];
    int cntchild = 0;
    for (auto next : G[cur]) {
      if (d[next] != -1) continue;
      d[next] = dist + 1;
      par[next] = cur;
      q.push(next);
      ++cntchild;
    }
    if (!cntchild) leaf.push_back(make_pair(-dist, cur));
  }
  sort((leaf).begin(), (leaf).end());
  int goal = NIL, lf = NIL;
  for (auto &l : leaf) {
    int ca = commonAncestor(u, l.second);
    if (distant(u, ca) < d[ca] && goal == NIL) goal = l.second;
    if (ca == u && lf == NIL) lf = l.second;
    if (goal != NIL && lf != NIL) break;
  }
  int cnt = 0;
  while (1) {
    if (goal == NIL) {
      if (u == lf) {
        u = par[u];
      } else {
        int dd = INF, nt = NIL;
        for (auto a : G[u]) {
          int ddd = distant(a, lf);
          if (dd > ddd) {
            dd = ddd;
            nt = a;
          }
        }
        u = nt;
      }
    } else {
      if (u == goal) {
        u = par[u];
      } else {
        int dd = INF, nt = NIL;
        for (auto a : G[u]) {
          int ddd = distant(a, goal);
          if (dd > ddd) {
            dd = ddd;
            nt = a;
          }
        }
        u = nt;
      }
    }
    if (v == u) break;
    int dd = INF, nt = NIL;
    for (auto a : G[v]) {
      int ddd = distant(a, u);
      if (dd > ddd) {
        dd = ddd;
        nt = a;
      }
    }
    v = nt;
    ++cnt;
    if (v == u) break;
  }
  cout << cnt << "\n";
  return 0;
}
