#include <bits/stdc++.h>
using namespace std;
;
const int MOD = 1000000007;
vector<long long> e[100005];
long long u, v;
vector<long long> disu(100005), disv(100005);
void caldis(long long x, long long from, long long dis, bool isu) {
  if (isu)
    disu[x] = dis;
  else
    disv[x] = dis;
  for (int i = 0; i < e[x].size(); i++) {
    long long to = e[x][i];
    if (to == from) continue;
    caldis(to, x, dis + 1, isu);
  }
}
bool can[100005];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n;
  cin >> n;
  cin >> u >> v;
  u--;
  v--;
  for (int i = 0; i < n - 1; i++) {
    long long a, b;
    cin >> a >> b;
    a--;
    b--;
    e[a].push_back(b);
    e[b].push_back(a);
  }
  caldis(u, -1, 0, true);
  caldis(v, -1, 0, false);
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    if (disu[i] < disv[i]) {
      ans = max(ans, (disu[i] + disv[i]) / 2);
    }
  }
  for (int i = 0; i < n; i++) {
    cerr << disu[i] << endl;
  }
  for (int i = 0; i < n; i++) {
    cerr << disv[i] << endl;
  }
  cout << ans << endl;
}
