#include <bits/stdc++.h>
using namespace std;
inline long long bip(long long x, long long n, long long mod) {
  long long res = 1;
  while (n) {
    if (n & 1) {
      res = (res * x) % mod;
    }
    x = (x * x) % mod;
    n >>= 1;
  }
  return res;
}
const int ppr = 257;
const long long INF = 2e18;
const int inf = 2e9;
const int mod = 1e9 + 7;
const int N = 1e5 + 123;
const long double pi = acos(-1.0);
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
int n, x, y, timer, p[18][N], tin[N], tout[N], d[N];
vector<int> g[N];
void dfs(int v, int pr = 0) {
  p[0][v] = pr;
  for (int i = 1; i < 17; i++) p[i][v] = p[i - 1][p[i - 1][v]];
  tin[v] = ++timer;
  for (int to : g[v]) {
    if (to == pr) continue;
    d[to] = d[v] + 1;
    dfs(to, v);
  }
  tout[v] = ++timer;
}
inline bool isp(int x, int y) {
  return (tin[x] <= tin[y] && tout[x] >= tout[y]);
}
inline int lca(int x, int y) {
  if (isp(x, y)) return x;
  if (isp(y, x)) return y;
  for (int i = 16; i >= 0; i--)
    if (p[i][x] && !isp(p[i][x], y)) x = p[i][x];
  return p[0][x];
}
inline int get(int x, int y) {
  int p = lca(x, y);
  return d[x] + d[y] - d[p] - d[p];
}
int ans;
int main() {
  cin >> n >> x >> y;
  for (int i = 1; i < n; i++) {
    int a, b;
    cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  dfs(1);
  ans = 1;
  for (int i = 1; i <= n; i++)
    if (g[i].size() == 1) {
      int a = get(i, x);
      int b = get(i, y);
      if (a >= b) continue;
      int x = b - a;
      ans = max(ans, min(a, b));
    }
  cout << ans;
  return 0;
}
