#include <bits/stdc++.h>
using namespace std;
vector<vector<long long>> g;
void dfs(long long v, long long p, vector<long long> &dist) {
  for (auto &u : g[v]) {
    if (u != p) {
      dist[u] = dist[v] + 1;
      dfs(u, v, dist);
    }
  }
}
long long timer = 0;
vector<long long> tin, tout;
void dfs2(long long v, long long p) {
  tin[v] = timer++;
  for (auto &u : g[v]) {
    if (u != p) {
      dfs2(u, v);
    }
  }
  tout[v] = timer++;
}
bool is_ancestor(long long u, long long v) {
  return tin[u] <= tin[v] && tout[u] >= tout[v];
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  long long n;
  cin >> n;
  g.resize(n);
  tin.resize(n), tout.resize(n);
  long long T, A;
  cin >> T >> A;
  T--, A--;
  for (long long i = 1; i < n; i++) {
    long long a, b;
    cin >> a >> b;
    a--, b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  dfs2(0, 0);
  vector<long long> distT(n, 0), distA(n, 0);
  dfs(T, T, distT);
  dfs(A, A, distA);
  vector<pair<long long, long long>> vvv(n);
  for (long long i = 0; i < n; i++) {
    vvv[i] = {tin[i], i};
  }
  sort(vvv.begin(), vvv.end());
  long long lca = 0;
  for (long long i = 0; i < n; i++) {
    if (is_ancestor(vvv[i].second, T) && is_ancestor(vvv[i].second, A))
      lca = vvv[i].second;
  }
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    if (distT[i] > distA[i]) {
      ans = max(ans, distT[i] - 1);
    } else if (distT[i] == distA[i] && distT[lca] != distA[lca]) {
      ans = max(ans, distT[i]);
    }
  }
  if (distT[lca] == distA[lca]) {
    ans = max(ans, distT[lca]);
  }
  cout << ans << "\n";
}
