#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using P = pair<i64, i64>;
const i64 INF = numeric_limits<i64>::max();
struct edge {
  i64 src, to, cost;
  edge(i64 to, i64 cost) : src(-1), to(to), cost(cost) {}
  edge(i64 src, i64 to, i64 cost) : src(src), to(to), cost(cost) {}
  bool operator<(const edge &u) { return this->cost < u.cost; };
};
using Graph = vector<vector<edge>>;
vector<i64> dijkstra(Graph G, i64 s) {
  i64 n = G.size();
  vector<i64> dist(n, INF);
  dist[s] = 0;
  priority_queue<P, vector<P>, greater<P>> que;
  que.emplace(0, s);
  while (!que.empty()) {
    P t = que.top();
    que.pop();
    i64 cost = t.first, u = t.second;
    if (cost > dist[u]) continue;
    for (auto e : G[u]) {
      i64 v = e.to;
      if (cost + e.cost < dist[v]) {
        dist[v] = cost + e.cost;
        que.emplace(dist[v], v);
      }
    }
  }
  return dist;
}
void solve(long long N, long long u, long long v, std::vector<long long> A,
           std::vector<long long> B) {
  Graph G(N);
  --u;
  --v;
  for (int i = 0; i < N - 1; ++i) {
    --A[i];
    --B[i];
    G[A[i]].push_back(edge(A[i], B[i], 1));
    G[B[i]].push_back(edge(B[i], A[i], 1));
  }
  vector<i64> da = dijkstra(G, u);
  vector<i64> db = dijkstra(G, v);
  queue<i64> que;
  que.push(u);
  vector<i64> d(N, INF);
  d[u] = 0;
  i64 ans = 0;
  while (!que.empty()) {
    i64 t = que.front();
    que.pop();
    if (d[t] >= db[t]) continue;
    for (auto e : G[t]) {
      i64 x = e.to;
      if (d[x] == INF) {
        if (d[t] + 1 < db[x]) {
          d[x] = d[t] + 1;
          que.push(x);
        } else if (d[t] + 1 == db[x]) {
          ans = max(ans, db[x]);
        }
      }
    }
  }
  for (int i = 0; i < N; ++i) {
    if (d[i] != INF) ans = max(ans, d[i]);
  }
  cout << ans << endl;
}
int main() {
  long long N;
  scanf("%lld", &N);
  long long u;
  scanf("%lld", &u);
  long long v;
  scanf("%lld", &v);
  std::vector<long long> A(N - 1);
  std::vector<long long> B(N - 1);
  for (int i = 0; i < N - 1; i++) {
    scanf("%lld", &A[i]);
    scanf("%lld", &B[i]);
  }
  solve(N, u, v, std::move(A), std::move(B));
  return 0;
}
