#include <bits/stdc++.h>
using namespace std;
const int MAXN = (int)1e5 + 10;
int n, s, t;
vector<int> adj[MAXN];
int ds[MAXN], dt[MAXN], f[MAXN];
void dfs(int u, int *d, int *f, int p = -1) {
  f[u] = 0;
  for (int i = 0; i < (int)adj[u].size(); ++i) {
    int v = adj[u][i];
    if (v != p) {
      d[v] = d[u] + 1;
      dfs(v, d, f, u);
      f[u] = max(f[u], f[v] + 1);
    }
  }
}
int main() {
  scanf("%d%d%d", &n, &s, &t);
  for (int i = 1; i <= n - 1; ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  dt[t] = 0;
  dfs(t, dt, f);
  ds[s] = 0;
  dfs(s, ds, f);
  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    if (ds[i] >= dt[i] || (ds[i] + dt[i] == ds[t])) {
      continue;
    }
    int len = ds[i] + f[i];
    ans = max(ans, dt[i] - 1);
  }
  for (int i = 1; i <= n; ++i) {
    if (ds[i] == dt[i] && ds[i] + dt[i] == ds[t]) {
      ans = max(ans, dt[i]);
    }
  }
  cout << ans << endl;
  return 0;
}
