#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;
using vb = vector<bool>;
using vc = vector<char>;
using vcc = vector<vc>;
using vP = vector<P>;
using vPP = vector<vP>;
using vPl = vector<Pl>;
const int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 62) - 1;
ll ceil(const ll &a, const ll &b) { return ((a) + (b)-1) / b; }
template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
void dfs(int v, vi &res, const vii tree) {
  for (int nv : tree[v]) {
    if (res[nv] != inf) continue;
    res[nv] = res[v] + 1;
    dfs(nv, res, tree);
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, u, v;
  cin >> n >> u >> v;
  u--;
  v--;
  vii tree(n);
  for (ll i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    tree[a].push_back(b);
    tree[b].push_back(a);
  }
  vi t(n, inf), a(n, inf);
  t[u] = 0, a[v] = 0;
  dfs(u, t, tree);
  dfs(v, a, tree);
  int ans = 0;
  for (ll i = 0; i < n; i++) {
    if (t[i] + 1 > a[i]) continue;
    int d = a[i];
    if (int(tree[i].size()) == 1) d--;
    chmax(ans, d);
  }
  cout << ans << '\n';
}
