#include <bits/stdc++.h>
using namespace std;
int n, u, v, a, b, y[100010], ans, mx;
vector<int> g[100010], z;
bool f[100010], ff;
void dfs(int x) {
  if (x == v) {
    ff = 1;
    return;
  }
  for (int i = 0; i < g[x].size(); i++)
    if (f[g[x][i]] == 0) {
      f[g[x][i]] = 1;
      z.push_back(g[x][i]);
      dfs(g[x][i]);
      if (ff == 1) return;
      z.erase(z.end() - 1);
    }
}
void dfs2(int x, int deep, int j) {
  y[j] = max(y[j], deep);
  for (int i = 0; i < g[x].size(); i++)
    if (f[g[x][i]] == 0) {
      f[g[x][i]] = 1;
      dfs2(g[x][i], deep + 1, j);
    }
}
int main() {
  cin >> n >> u >> v;
  for (int i = 0; i < n - 1; i++) {
    cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  z.push_back(u);
  f[u] = 0;
  dfs(u);
  f[u] = 1;
  for (int i = 0; i < z.size(); i++) {
    memset(f, 0, sizeof(f));
    if (i > 0) f[z[i - 1]] = 1;
    if (i < z.size() - 1) f[z[i + 1]] = 1;
    f[z[i]] = 1;
    dfs2(z[i], 0, i);
  }
  a = 0;
  b = z.size() - 1;
  while (b - a > 1) {
    a++;
    b--;
    ans++;
  }
  if (a == b) a--, b++, ans--;
  for (int i = 0; i <= a; i++) mx = max(mx, y[i] + a - i);
  cout << ans + mx + b - a - 1 << endl;
  return 0;
}
