#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int n;
int U, V;
bool mark[maxn];
int f[20][maxn];
int height[maxn];
vector<int> adj[maxn];
int dp[maxn], DP[maxn];
int ans;
void in();
void solve();
void dfs(int u);
void calcDP(int u);
void calcf();
int lca(int u, int v);
int father(int u, int t);
void out();
int main() {
  in();
  solve();
  out();
}
void in() {
  ios::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
  cin >> n >> U >> V;
  U--;
  V--;
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  memset(f, -1, sizeof f);
  dfs(0);
  calcDP(0);
  calcf();
}
void solve() {
  int x = lca(U, V);
  int disV = height[V] - height[x];
  int disU = height[U] - height[x];
  if (disV <= disU) {
    ans += (disV + disU - 1) / 2;
    U = father(U, (disV + disU - 1) / 2);
    ans += dp[U];
    if ((disU + disV) % 2 == 0) ans++;
  } else {
    ans += (disV + disU - 1) / 2;
    U = father(V, (disV + disU - 1) / 2);
    if ((disU + disV) % 2 == 0) {
      ans++;
      U = f[0][U];
    }
    ans += DP[U];
  }
}
void dfs(int u) {
  mark[u] = 1;
  for (auto v : adj[u]) {
    if (!mark[v]) {
      f[0][v] = u;
      height[v] = height[u] + 1;
      dfs(v);
      dp[u] = max(dp[v] + 1, dp[u]);
    }
  }
}
void calcDP(int u) {
  mark[u] = 0;
  for (auto v : adj[u]) {
    if (mark[v]) {
      for (auto v2 : adj[u])
        if (mark[v2]) DP[v] = max(DP[v], dp[v]);
      if (u != 0) DP[v] = max(DP[v], 1 + DP[u]);
    }
  }
  for (auto v : adj[u])
    if (mark[v]) calcDP(v);
}
void calcf() {
  for (int i = 1; i < 20; i++)
    for (int j = 0; j < n; j++)
      if (f[i - 1][j] != -1) f[i][j] = f[i - 1][f[i - 1][j]];
}
int lca(int u, int v) {
  if (height[u] > height[v]) swap(u, v);
  for (int i = 19; i >= 0; i--)
    if (f[i][v] != -1 && height[f[i][v]] >= height[u]) v = f[i][v];
  if (u == v) return u;
  for (int i = 19; i >= 0; i--) {
    if (f[i][v] != -1 && f[i][v] != f[i][u]) {
      v = f[i][v];
      u = f[i][u];
    }
  }
  return f[0][u];
}
int father(int u, int t) {
  for (int i = 19; i >= 0; i--) {
    if (f[i][u] != -1 && height[u] - height[f[i][u]] <= t) {
      t -= height[u] - height[f[i][u]];
      u = f[i][u];
    }
  }
  return u;
}
void out() { cout << ans; }
