#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
const long long INF = 1LL << 60;
const int MAX_V = 200000;
struct edge {
  long long to;
  long long cost;
};
vector<vector<edge>> G(MAX_V);
vector<long long> dijkstra(long long s, long long N) {
  vector<long long> value(N, INF);
  priority_queue<pair<int, int>, vector<pair<int, int>>,
                 greater<pair<int, int>>>
      que;
  que.push(pair<int, int>(0, s));
  value[s] = 0;
  while (!que.empty()) {
    pair<int, int> p = que.top();
    que.pop();
    long long v = p.second;
    if (value[v] < p.first) {
      continue;
    }
    for (int i = (0); i < (G[v].size()); i++) {
      edge e = G[v][i];
      if (value[e.to] > value[v] + e.cost) {
        value[e.to] = value[v] + e.cost;
        que.push(pair<int, int>(value[e.to], e.to));
      }
    }
  }
  return value;
}
int main() {
  int N, u, v;
  cin >> N >> u >> v;
  u--;
  v--;
  for (int i = (0); i < (N - 1); i++) {
    int A, B;
    cin >> A >> B;
    A--;
    B--;
    G[A].push_back({B, 1});
    G[B].push_back({A, 1});
  }
  auto du = dijkstra(u, N);
  auto dv = dijkstra(v, N);
  long long a1 = INF;
  for (int i = (0); i < (N); i++) {
    if (du[i] == dv[i]) chmin(a1, du[i]);
  }
  if (a1 != INF) {
    cout << a1 << endl;
    return 0;
  }
  long long a2 = 0;
  for (int i = (0); i < (N); i++) {
    if ((int)G[i].size() <= 1) continue;
    if (dv[i] > du[i]) chmax(a2, dv[i]);
  }
  long long ans = a2;
  if (a1 != INF && a2 == 0) ans = a1;
  cout << ans << endl;
  return 0;
}
