#include <bits/stdc++.h>
using namespace std;
const long long dx[] = {0, -1, 0, 1};
const long long dy[] = {1, 0, -1, 0};
const long long MOD = (1000000007);
const long long INF = (1LL << 60) - 1;
const double EPS = (1 >> 30);
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
using Graph = vector<vector<pair<long long, long long>>>;
using Ki = vector<vector<long long>>;
using Vi = vector<long long>;
vector<long long> dijkstra(long long s, Graph& G) {
  priority_queue<pair<long long, long long>, vector<pair<long long, long long>>,
                 greater<pair<long long, long long>>>
      que;
  long long n = G.size();
  vector<long long> dist(n);
  dist.assign(n, INF);
  dist[s] = 0;
  que.push(pair<long long, long long>(0, s));
  while (!que.empty()) {
    pair<long long, long long> p = que.top();
    que.pop();
    long long v = p.second;
    for (long long i = 0; i < G[v].size(); i++) {
      if (dist[G[v][i].first] > dist[v] + G[v][i].second) {
        dist[G[v][i].first] = dist[v] + G[v][i].second;
        que.push(
            pair<long long, long long>(dist[G[v][i].first], G[v][i].first));
      }
    }
  }
  return dist;
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(10);
  long long n, u, v;
  cin >> n >> u >> v;
  Graph G(n);
  for (long long i = 0; i < n - 1; i++) {
    long long a, b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(pair<long long, long long>(b, 1));
    G[b].push_back(pair<long long, long long>(a, 1));
  }
  Vi oi = dijkstra(v - 1, G);
  Vi nige = dijkstra(u - 1, G);
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    if (oi[i] - nige[i] < 0) continue;
    ans = max(ans, oi[i] - 1);
  }
  cout << ans << endl;
}
