#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;
template <typename T>
vector<T> Dijkstra(int s, vector<vector<pair<int, T>>>& G, const T INF = 1e9) {
  using pair<int, int> = pair<T, int>;
  int V = G.size();
  vector<T> dist(V, INF);
  priority_queue<pair<int, int>, vector<pair<int, int>>,
                 greater<pair<int, int>>>
      que;
  dist[s] = 0;
  que.emplace(0, s);
  while (!que.empty()) {
    pair<int, int> p = que.top();
    que.pop();
    int v = p.second;
    if (dist[v] < p.first) continue;
    for (int i = 0; i < G[v].size(); i++) {
      int to = G[v][i].first;
      T cost = G[v][i].second;
      if (dist[to] > dist[v] + cost) {
        dist[to] = dist[v] + cost;
        que.emplace(dist[to], to);
      }
    }
  }
  return dist;
}
signed main() {
  int n, u, v;
  cin >> n >> u >> v;
  u--;
  v--;
  vector<vector<pair<int, int>>> G(n);
  for (int i = 0; i < (n - 1); i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    G[a].emplace_back(b, 1);
    G[b].emplace_back(a, 1);
  }
  vector<int> distt = Dijkstra<int>(u, G);
  vector<int> dista = Dijkstra<int>(v, G);
  int ans = 0;
  for (int i = 0; i < (n); i++) {
    if (distt[i] <= dista[i]) {
      ans = max(ans, distt[i]);
    }
  }
  cout << ans << endl;
  return 0;
}
