#include <bits/stdc++.h>
using namespace std;
int N;
vector<int> to[100005];
vector<int> dist;
void dfs(int v, int d = 0, int p = -1) {
  dist[v] = d;
  for (int u : to[v]) {
    if (u == p) continue;
    dfs(u, d + 1, v);
  }
}
vector<int> calcDist(int s) {
  dist = vector<int>(N);
  dfs(s);
  return dist;
}
int main() {
  cin >> N;
  int u, v;
  cin >> u >> v;
  --u;
  --v;
  for (int i = 0; i < N - 1; i++) {
    int A, B;
    cin >> A >> B;
    --A;
    --B;
    to[A].push_back(B);
    to[B].push_back(A);
  }
  vector<int> dist_U = calcDist(u);
  vector<int> dist_V = calcDist(v);
  int mx = 0;
  for (int i = 0; i < N; i++) {
    if (dist_U[i] > dist_V[i]) {
      mx = max(mx, dist_U[i]);
    }
  }
  int ans = mx - 1;
  cout << ans << endl;
  return 0;
}
