#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long power(long long x, long long y, long long p) {
  long long res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
const long long L = 1e5 + 5;
const long long logn = 20;
long long parent[L];
long long dp[L][logn + 5];
vector<long long> ad[L];
long long vis[L];
long long depth[L];
void dfs(long long ind, long long par) {
  vis[ind] = 1;
  parent[ind] = par;
  for (long long v : ad[ind]) {
    if (!vis[v]) {
      depth[v] = depth[ind] + 1;
      dfs(v, ind);
    }
  }
}
long long lca(long long u, long long v) {
  if (depth[u] < depth[v]) swap(u, v);
  long long dist = depth[u] - depth[v];
  for (long long i = logn; i >= 0; i--) {
    long long temp = dist - (1 << i);
    if (temp >= 0) {
      dist -= (1 << i);
      u = dp[u][i];
    }
  }
  if (u == v) return u;
  for (long long i = logn; i >= 0; i--) {
    if (dp[u][i] != dp[v][i]) {
      u = dp[u][i];
      v = dp[v][i];
    }
  }
  return parent[u];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, u, v;
  cin >> n >> u >> v;
  u--, v--;
  depth[v] = 0;
  long long x, y;
  for (long long i = 1; i < n; i++) {
    cin >> x >> y;
    x--, y--;
    ad[x].push_back(y);
    ad[y].push_back(x);
  }
  dfs(v, v);
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j <= logn; j++) {
      dp[i][j] = 0;
    }
  }
  long long mxd = depth[u];
  long long mxi = u;
  for (long long i = 0; i < n; i++) {
    if (depth[i] > mxd) {
      mxd = depth[i];
      mxi = i;
    }
    dp[i][0] = parent[i];
  }
  for (long long j = 1; j <= logn; j++) {
    for (long long i = 0; i < n; i++) {
      dp[i][j] = dp[dp[i][j - 1]][j - 1];
    }
  }
  long long ans;
  if (mxi == u) {
    ans = depth[u] - 1;
  } else {
    long long com = lca(u, mxi);
    long long dist1 = depth[com];
    long long dist2 = depth[u] - depth[com];
    if (dist1 > dist2) {
      ans = mxd - 1;
    } else {
      ans = depth[u] - 1;
    }
  }
  cout << ans << '\n';
  return 0;
}
