#include <bits/stdc++.h>
using namespace std;
const int N = (1e5) + 5;
vector<int> adj[N];
int n, u, v;
bool vis[N];
void dfs(int u, bool paint, int p = -1) {
  vis[u] = paint;
  for (int i = 0; i < (int)adj[u].size(); ++i) {
    int v = adj[u][i];
    if (v != p) {
      dfs(v, !paint, u);
    }
  }
}
void dfs2(int u, int h, bool paint, int p = -1) {
  if (h >= 0 and vis[u]) {
    vis[u] = 0;
  }
  for (int i = 0; i < (int)adj[u].size(); ++i) {
    int v = adj[u][i];
    if (v != p) {
      dfs2(v, h - 1, !paint, u);
    }
  }
}
long long f(long long x) {
  memset(vis, 0, sizeof(bool) * n);
  dfs(u, !(x & 1));
  int cnt = 0;
  dfs2(v, x, 1);
  for (int u = 0; u < n; ++u) {
    cnt += !vis[u];
  }
  if (cnt != n) {
    memset(vis, 0, sizeof(bool) * n);
    dfs(u, !((x + 1) & 1));
    int cnt = 0;
    dfs2(v, x, 1);
    for (int u = 0; u < n; ++u) {
      cnt += !vis[u];
    }
    return cnt == n;
  }
  return 1;
}
bool predicate(long long mid, long long y) { return (y <= f(mid)); }
long long bs(long long lo, long long hi, long long y = 1) {
  if (predicate(lo, y)) return lo;
  if (!predicate(hi, y)) return hi + 1;
  while (hi - lo > 1) {
    long long mid = lo + ((hi - lo) >> 1);
    if (predicate(mid, y))
      hi = mid;
    else
      lo = mid;
  }
  return hi;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> u >> v;
  --u;
  --v;
  for (int i = 0; i < n - 1; ++i) {
    int u, v;
    cin >> u >> v;
    --u;
    --v;
    adj[u].emplace_back(v);
    adj[v].emplace_back(u);
  }
  cout << bs(0, n) << "\n";
  return 0;
}
