#include <bits/stdc++.h>
using namespace std;
const unsigned long long mod = 1000000007;
long long n, u, v;
vector<vector<long long>> g;
vector<long long> distU;
vector<long long> distV;
void dfsU(long long current, long long d) {
  if (distU[current] != -1) return;
  distU[current] = d;
  if (current == v) return;
  for (auto e : g[current]) {
    dfsU(e, d + 1);
  }
}
void dfsV(long long current, long long d) {
  if (distV[current] != -1) return;
  distV[current] = d;
  for (auto e : g[current]) {
    dfsV(e, d + 1);
  }
}
int main(void) {
  cin >> n >> u >> v;
  g.resize(n + 1);
  distU.resize(n + 1, -1);
  distV.resize(n + 1, -1);
  for (int i = 0; i < n - 1; i++) {
    long long a, b;
    cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  dfsU(u, 0);
  dfsV(v, 0);
  long long ma = 0;
  for (int i = 1; i <= n; i++) {
    if (distU[i] == -1) continue;
    ma = max(ma, max(0LL, distV[i] - 1));
  }
  cout << ma << endl;
  return 0;
}
