#include <bits/stdc++.h>
using namespace std;
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;
  for (uint64_t n = 0; n < N; ++n) {
    edges[n] = set<uint64_t>();
  }
  for (uint64_t n = 0; n < N - 1; ++n) {
    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;
  for (uint64_t n = 0; n < N; ++n) {
    if (n == start_v) {
      continue;
    }
    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;
      }
    }
  }
  cout << (Q[farest_leaf] - 1) << endl;
  return 0;
}
