#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
const long long INF = 0x3f3f3f3f3f3f3f3f;
const long long llinf = (1LL << 62);
const int inf = (1 << 30);
const int nmax = 1e5 + 50;
const int mod = 1e9 + 7;
using namespace std;
int n, i, x, y, u, v, rs, pr[nmax], mx;
bitset<nmax> viz, viz1;
vector<int> vc, vc1, a[nmax];
void dfs(int x, int p) {
  pr[x] = p;
  for (int i = 0; i < (int)a[x].size(); i++)
    if (a[x][i] != p) dfs(a[x][i], x);
}
void get(int x, int l) {
  viz[x] = 1;
  for (int i = 0; i < (int)a[x].size(); i++)
    if (!viz[a[x][i]]) get(a[x][i], l + 1);
  mx = max(mx, l);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cerr.tie(0);
  cout.tie(0);
  cin >> n >> u >> v;
  for (i = 1; i < n; i++) {
    cin >> x >> y;
    a[x].push_back(y);
    a[y].push_back(x);
  }
  dfs(1, 0);
  x = v;
  while (x) {
    viz[x] = 1;
    x = pr[x];
  }
  x = u;
  while (1) {
    vc.push_back(x);
    viz1[x] = 1;
    if (viz[x]) break;
    x = pr[x];
  }
  y = x, x = v;
  while (x != y) {
    vc1.push_back(x);
    x = pr[x];
  }
  reverse(vc1.begin(), vc1.end());
  for (i = 0; i < (int)vc1.size(); i++) vc.push_back(vc1[i]);
  rs = (int)vc.size() / 2 - 1;
  x = vc[rs];
  viz.reset(), viz1.reset();
  viz[vc[rs + 1]] = 1;
  get(x, 0);
  rs += mx + (mx & 1);
  if ((int)vc.size() > 2) rs = max(rs, 1);
  cout << rs << endl;
  return 0;
}
