#include <bits/stdc++.h>
using namespace std;
int n;
int u;
int v;
vector<vector<int>> e;
vector<int> ad;
vector<int> bd;
vector<int> cd;
vector<int> dd;
int amd, ami, amd2;
int ans;
void dfs1(int n, int d) {
  if (bd[n] >= 0) return;
  bd[n] = d;
  for (int nx : e[n]) {
    dfs1(nx, d + 1);
  }
}
void dfs2(int n, int d) {
  if (ad[n] >= 0) return;
  ad[n] = d;
  if (d < bd[n] && d > amd) {
    amd = d;
    ami = n;
  }
  if (d <= bd[n]) {
    ans = max(ans, d);
  }
  if (d >= bd[n]) return;
  for (int nx : e[n]) {
    dfs2(nx, d + 1);
  }
}
void dfs3(int n, int d) {
  if (cd[n] >= 0) return;
  cd[n] = d;
  if (d <= bd[n]) {
    ans = max(ans, d);
    if (d < bd[n] && d > amd2) {
      amd2 = d;
      ami = n;
    }
  }
  if (d >= bd[n]) return;
  for (int nx : e[n]) {
    dfs3(nx, d + 1);
  }
}
void dfs4(int n, int d) {
  if (dd[n] >= 0) return;
  dd[n] = d;
  if (d <= bd[n]) {
    ans = max(ans, d);
  }
  if (d >= bd[n]) return;
  for (int nx : e[n]) {
    dfs4(nx, d + 1);
  }
}
int main(int argc, char* argv[]) {
  cout.precision(20);
  {
    ans = 0;
    n = -1;
    cin >> n >> u >> v;
    if (n <= 0) return 0;
    e.clear();
    e.resize(n);
    for (int i = 1; i < n; ++i) {
      int a, b;
      cin >> a >> b;
      e[a - 1].push_back(b - 1);
      e[b - 1].push_back(a - 1);
    }
    ad = vector<int>(n, -1);
    bd = vector<int>(n, -1);
    cd = vector<int>(n, -1);
    dd = vector<int>(n, -1);
    dfs1(v - 1, 0);
    amd = -1;
    dfs2(u - 1, 0);
    if (amd > 0) {
      amd2 = -1;
      dfs3(ami, amd);
      if (amd2 > 0) {
        dfs4(ami, amd2);
      }
    }
    cout << ans << endl;
  }
  return 0;
}
