#include <bits/stdc++.h>
#include <bits/stdint-uintn.h>

using namespace std;

#define N_TIMES(i, n)     for ( uint64_t i = 0;     i <  n; ++i )
#define N_TIMES_REV(i, n) for (  int64_t i = n - 1; i >= 0; --i )

uint64_t calc_dist(uint64_t N, const map<uint64_t, set<uint64_t>> &edges, uint64_t start, vector<uint64_t> &dist)
{
  queue<pair<uint64_t, uint64_t>> q;

  dist[start] = 0;
  q.emplace(start, 0);

  while (!q.empty()) {
    pair<uint64_t, uint64_t> p = q.front(); q.pop();

    for (const uint64_t &v : edges.at(p.first)) {
      if (dist[v] < p.second + 1) { continue; }

      dist[v] = p.second + 1;
      q.emplace(v, p.second + 1);
    }
  }

  return 0;
}

int main()
{
  uint64_t N, start_u, start_v;
  cin >> N >> start_u >> start_v;
  --start_u; --start_v;

  map<uint64_t, set<uint64_t>> edges;
  N_TIMES(n, N) { edges[n] = set<uint64_t>(); }
  N_TIMES(n, N - 1) {
    uint64_t a, b;
    cin >> a >> b;

    edges[a - 1].insert(b - 1);
    edges[b - 1].insert(a - 1);
  }

  if (edges[start_u].size() == 1) {
    uint64_t v = *edges[start_u].begin();
    if (v == start_v) {
      cout << 0 << endl;
      return 0;
    }
  }

  set<uint64_t> leaves;
  N_TIMES (n, N) {
    if (edges[n].size() == 1) { leaves.insert(n); }
  }

  vector<uint64_t> P(N, -1), Q(N, -1);
  calc_dist(N, edges, start_u, P);
  calc_dist(N, edges, start_v, Q);

  uint64_t farest_leaf = *leaves.begin();
  for (uint64_t leaf : leaves) {
    if (P[leaf] <= Q[leaf]) {
      if (Q[farest_leaf] <= Q[leaf]) {
        farest_leaf = leaf;
      }
    }
  }

  uint64_t x = *edges[farest_leaf].begin();
  cout << Q[x] << endl;

  return 0;
}