#include <bits/stdc++.h>
using namespace std;
int const maxn = 1e5 + 5, logg = 20;
vector<int> g[maxn];
int h[maxn], was[maxn], H[maxn], mxh[maxn];
int dp[maxn][logg];
void dfs(int v, int p) {
  dp[v][0] = p;
  h[v] = h[p] + 1;
  mxh[v] = h[v];
  for (int i = 1; i < logg; ++i) dp[v][i] = dp[dp[v][i - 1]][i - 1];
  for (auto u : g[v])
    if (u != p) dfs(u, v), mxh[v] = max(mxh[v], mxh[u]);
}
int get_la(int u, int x) {
  for (int i = 0; i < logg; ++i) {
    if ((x & (1 << i)) > 0) u = dp[u][i];
  }
  return u;
}
int get_lca(int v, int u) {
  if (h[v] > h[u])
    v = get_la(v, h[v] - h[u]);
  else
    u = get_la(u, h[u] - h[v]);
  if (u == v) return u;
  for (int i = logg - 1; i >= 0; --i) {
    if (dp[u][i] != dp[v][i]) u = dp[u][i], v = dp[v][i];
  }
  return dp[u][0];
}
int get(int v) {
  for (auto u : g[v]) {
    if (dp[v][0] != u && mxh[u] == mxh[v]) {
      return get(u);
    }
  }
  return v;
}
void dfs1(int v, int hh) {
  was[v] = 1;
  H[v] = hh;
  for (auto u : g[v]) {
    if (was[u] != 0) continue;
    dfs1(u, hh + 1);
  }
}
void go(int v, int p) {
  was[v] = 1;
  for (auto u : g[v])
    if (u != p) go(u, v);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, x, y, u, v;
  cin >> n >> x >> y;
  for (int i = 1; i < n; ++i) {
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  dfs(1, 0);
  int t = get_lca(x, y);
  if (h[x] - h[t] >= h[y] - h[t]) {
    for (auto u : g[t]) {
      if (dp[t][0] == u) continue;
      if (get_lca(u, x) == u) go(u, t);
    }
    int ans = 0;
    for (int i = 1; i <= n; ++i) {
      if (was[i] != 1) continue;
      int dist1 = h[i] + h[x] - 2 * h[get_lca(i, x)];
      int dist2 = h[y] + h[i] - 2 * h[get_lca(i, y)];
      ans = max(ans, dist2 - 1);
    }
    cout << ans << '\n';
  } else {
    for (auto u : g[v]) {
      if (dp[v][0] == u) continue;
      if (get_lca(u, y) == u) was[u] = 2;
    }
    dfs1(t, 0);
    int ans = 0;
    for (int i = 1; i <= n; ++i) {
      if (was[i] != 1) continue;
      int dist1 = h[i] + h[x] - 2 * h[get_lca(i, x)];
      int dist2 = h[y] + h[i] - 2 * h[get_lca(i, y)];
      ans = max(ans, dist2 - 1);
    }
    cout << ans << '\n';
  }
  return 0;
}
