#include <bits/stdc++.h>
using namespace std;
long long n, u, v;
vector<long long> edge[100005];
vector<long long> disu, disv;
queue<long long> qu;
long long solve();
int main() {
  cin >> n >> u >> v;
  --u, --v;
  for (int i = 0; i < n - 1; ++i) {
    int a, b;
    cin >> a >> b;
    edge[--a].push_back(--b);
    edge[b].push_back(a);
  }
  cout << solve() << endl;
  return 0;
}
long long solve() {
  long long res = 0, id = u;
  disv.assign(n, (long long)1e9);
  disv[v] = 0;
  qu.push(v);
  while (!qu.empty()) {
    long long now = qu.front();
    qu.pop();
    for (long long nextp : edge[now])
      if (disv[nextp] > disv[now] + 1) {
        disv[nextp] = disv[now] + 1;
        qu.push(nextp);
      }
  }
  disu.assign(n, (long long)1e9);
  disu[u] = 0;
  qu.push(u);
  while (!qu.empty()) {
    long long now = qu.front();
    qu.pop();
    for (long long nextp : edge[now])
      if (disu[nextp] > disu[now] + 1 && disu[now] + 1 < disv[nextp]) {
        disu[nextp] = disu[now] + 1;
        qu.push(nextp);
        id = nextp;
      }
  }
  for (int i = 0; i < n; ++i)
    if (disu[i] != (long long)1e9) {
      long long now = 0;
      now = disu[i];
      now += (disv[i] - disu[i]) / 2;
      res = max(res, now);
    }
  return res;
}
