#include <bits/stdc++.h>
using namespace std;
void bfs(long long i, long long f, vector<long long> e[],
         vector<long long> &parent, long long n) {
  vector<bool> visited(n, false);
  queue<long long> q;
  q.push(i);
  visited[i] = true;
  while (visited[f] == false && q.empty() == false) {
    long long fr;
    fr = q.front();
    q.pop();
    for (auto &j : e[fr]) {
      if (visited[j] == false) {
        visited[j] = true;
        q.push(j);
        parent[j] = fr;
      }
    }
  }
}
long long height(long long i, vector<long long> edges[], long long x) {
  if (edges[i].size() == 1) return 1;
  long long ans = 0;
  for (auto &j : edges[i]) {
    if (j != x) ans = max(ans, height(j, edges, i) + 1);
  }
  return ans;
}
int32_t main() {
  long long n, f, i;
  cin >> n >> f >> i;
  f--;
  i--;
  vector<long long> e[n];
  for (long long i = 0; i < n - 1; i++) {
    long long a, b;
    cin >> a >> b;
    a--;
    b--;
    e[a].push_back(b);
    e[b].push_back(a);
  }
  vector<long long> parent(n, -1);
  bfs(i, f, e, parent, n);
  parent[i] = i;
  vector<long long> path1;
  long long k = f;
  while (parent[k] != k) {
    path1.push_back(k);
    k = parent[k];
  }
  path1.push_back(k);
  reverse(path1.begin(), path1.end());
  long long ans = INT_MIN;
  long long leave = ((long long)path1.size() + 1) / 2;
  long long extra = leave;
  long long discard;
  for (auto &j : path1) {
    if (leave > 0) {
      leave--, discard = j;
    } else {
      ans = max(ans, height(j, e, discard) - 2 + extra);
      discard = j;
      extra++;
    }
  }
  cout << ans;
}
