#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, u, v;
  std::cin >> n >> u >> v;
  u--;
  v--;
  vector<vector<long long>> edges(n);
  vector<long long> dist1(n, -1);
  vector<long long> dist2(n, -1);
  for (int i = 0; i < n - 1; i++) {
    long long a, b;
    std::cin >> a >> b;
    a--;
    b--;
    edges[a].push_back(b);
    edges[b].push_back(a);
  }
  queue<long long> q1;
  q1.push(u);
  dist1[u] = 0;
  while (q1.size()) {
    long long now = q1.front();
    q1.pop();
    for (auto e : edges[now]) {
      if (dist1[e] == -1) {
        dist1[e] = dist1[now] + 1;
        q1.push(e);
      }
    }
  }
  queue<long long> q2;
  q2.push(v);
  dist2[v] = 0;
  while (q2.size()) {
    long long now = q2.front();
    q2.pop();
    for (auto e : edges[now]) {
      if (dist2[e] == -1) {
        dist2[e] = dist2[now] + 1;
        q2.push(e);
      }
    }
  }
  long long res = 0;
  if (edges[u].size() == 1 && dist2[u] == 2) {
    std::cout << 1 << std::endl;
    return 0;
  }
  for (int i = 0; i < n; i++) {
    cerr << dist1[i] << " " << dist2[i] << endl;
  }
  for (int i = 0; i < n; i++) {
    if (dist1[i] < dist2[i]) {
      if ((dist1[i] - dist2[i]) % 2 == 0) {
        res = max(res, dist2[i]);
      } else {
        res = max(res, dist2[i] - 1);
      }
    }
  }
  std::cout << res << std::endl;
}
