#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, u, v;
  cin >> n >> u >> v;
  u--;
  v--;
  vector<vector<long long> > edge(n, vector<long long>(0));
  for (long long(i) = 0; (i) < (n - 1); (i)++) {
    long long a, b;
    cin >> a >> b;
    a--;
    b--;
    edge[a].push_back(b);
    edge[b].push_back(a);
  }
  vector<long long> dist(n, 1e9);
  dist[v] = 0;
  queue<long long> que;
  que.push(v);
  while (!que.empty()) {
    long long node = que.front();
    que.pop();
    for (long long(i) = 0; (i) < (edge[node].size()); (i)++) {
      long long ch = edge[node][i];
      if (dist[ch] != 1e9) continue;
      dist[ch] = dist[node] + 1;
      que.push(ch);
    }
  }
  long long ans = 0;
  for (long long(i) = 0; (i) < (n); (i)++) {
    ans = max((ans), (dist[i]));
  }
  cout << ans - 1 << endl;
  return 0;
}
