#include <bits/stdc++.h>
using namespace std;
const int N = 100 * 1000 + 5;
vector<int> v[N];
vector<int> par(N), dp(N);
int t, a, dist;
void dfs(int s, int pr, int c) {
  dp[s] = 0;
  par[s] = pr;
  if (s == t) {
    dist = c;
  }
  for (auto g : v[s]) {
    if (g != pr) {
      dfs(g, s, c + 1);
      dp[s] = max(dp[s], dp[g] + 1);
    }
  }
}
int main() {
  int n;
  cin >> n >> t >> a;
  for (int i = 0; i < n - 1; i++) {
    int x, y;
    cin >> x >> y;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  dfs(a, 0, 0);
  if (dist == 2) {
    cout << dp[t] + 1 * (dp[t] != 0);
    return 0;
  }
  int c = (dist - 1) / 2;
  while (c != 0) {
    t = par[t];
    c--;
  }
  cout << max(dp[t] + (dist - 1) / 2, dist / 2);
}
