#include <bits/stdc++.h>
using namespace std;
const long long big = 1e18;
void solve() {
  long long n, v, u;
  cin >> n >> v >> u;
  --v;
  --u;
  vector<vector<long long> > g(n);
  for (long long i = 0; i < n - 1; ++i) {
    long long tv, tu;
    cin >> tv >> tu;
    --tv;
    --tu;
    g[tv].push_back(tu);
    g[tu].push_back(tv);
  }
  vector<long long> dist1(n, big), dist2(n, big);
  queue<long long> q;
  q.push(v);
  dist1[v] = 0;
  while (!q.empty()) {
    long long tv = q.front();
    q.pop();
    for (auto tu : g[tv]) {
      if (dist1[tu] > dist1[tv] + 1) {
        dist1[tu] = dist1[tv] + 1;
        q.push(tu);
      }
    }
  }
  q.push(u);
  dist2[u] = 0;
  while (!q.empty()) {
    long long tv = q.front();
    q.pop();
    for (auto tu : g[tv]) {
      if (dist2[tu] > dist2[tv] + 1) {
        dist2[tu] = dist2[tv] + 1;
        q.push(tu);
      }
    }
  }
  long long ma = dist2[0], bv = 0;
  for (long long i = 1; i < n; ++i) {
    if (g[i].size() == 1 && ma < dist2[i] && dist1[i] < dist2[i]) {
      ma = dist2[i];
      bv = i;
    }
  }
  cout << ma - 1;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  solve();
  return 0;
}
