#include <bits/stdc++.h>
using namespace std;
long long MOD = 1000000007;
void dfs(int now, int d, vector<int> &dist, vector<vector<int> > &edges,
         vector<int> &cut) {
  if (dist[now] != 100000 || cut[now] > 0) {
    if (cut[now] == 1) {
      dist[now] = d;
    }
    return;
  }
  dist[now] = d;
  for (int i = 0; i < (int)edges[now].size(); i++) {
    int next_ = edges[now][i];
    dfs(next_, d + 1, dist, edges, cut);
  }
}
template <typename T>
void cout_vec(vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) {
    if (i != 0) {
      cout << ' ';
    }
    cout << vec[i];
  }
  cout << endl;
}
int main() {
  int N, u, v;
  cin >> N >> u >> v;
  u--;
  v--;
  vector<vector<int> > edges(N, vector<int>(0));
  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> t_dist(N, 100000);
  vector<int> a_dist(N, 100000);
  vector<int> cut(N, 0);
  dfs(u, 0, t_dist, edges, cut);
  dfs(v, 0, a_dist, edges, cut);
  for (int i = 0; i < N; i++) {
    if (t_dist[i] > a_dist[i]) {
      cut[i] = 2;
    } else if (t_dist[i] == a_dist[i]) {
      cut[i] = 1;
    }
  }
  a_dist = vector<int>(N, 100000);
  dfs(u, 0, a_dist, edges, cut);
  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (a_dist[i] == 100000) continue;
    ans = max(ans, a_dist[i]);
  }
  cout << ans << endl;
}
