#include <bits/stdc++.h>
using namespace std;
void shortestPath(const vector<vector<int> >& edges, int start,
                  vector<int>& dist) {
  int n = edges.size();
  dist.assign(n, INT_MAX);
  dist[start] = 0;
  queue<int> q;
  q.push(start);
  while (!q.empty()) {
    int v = q.front();
    q.pop();
    for (unsigned i = 0; i < edges[v].size(); ++i) {
      int u = edges[v][i];
      if (dist[u] == INT_MAX) {
        dist[u] = dist[v] + 1;
        q.push(u);
      }
    }
  }
}
int main() {
  int n, u, v;
  cin >> n >> u >> v;
  --u;
  --v;
  vector<vector<int> > edges(n);
  for (int i = 0; i < n - 1; ++i) {
    int a, b;
    cin >> a >> b;
    --a;
    --b;
    edges[a].push_back(b);
    edges[b].push_back(a);
  }
  vector<int> dist1, dist2;
  shortestPath(edges, u, dist1);
  shortestPath(edges, v, dist2);
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    if (dist1[i] % 2 == dist2[i] % 2) {
      bool ok = true;
      for (int j : edges[i]) {
        if (dist2[j] < dist2[i] && dist1[j] == dist2[j]) ok = false;
      }
      if (ok) ans = max(ans, dist2[i]);
    } else {
      ans = max(ans, dist2[i] - 1);
    }
  }
  cout << ans << endl;
  return 0;
}
