#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;
template <typename T>
void printv(const vector<T>& v) {
  int sz = v.size();
  for (int i = 0; i < sz; i++) {
    cout << v[i] << " \n"[i == sz - 1];
  }
}
using Graph = vector<vector<int>>;
const int N_MAX = 100010;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, u, v;
  cin >> n >> u >> v;
  u--;
  v--;
  Graph g(n);
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  vector<int> d(n, INF), par(n, -1);
  queue<int> que;
  d[v] = 0;
  que.push(v);
  while (!que.empty()) {
    int cur = que.front();
    que.pop();
    for (auto nxt : g[cur]) {
      if (d[nxt] != INF) continue;
      d[nxt] = d[cur] + 1;
      par[nxt] = cur;
      que.push(nxt);
    }
  }
  int pos = u;
  for (int i = 0; i < (d[u] - 1) / 2; i++) {
    pos = par[pos];
  }
  int ret = d[u] / 2;
  vector<int> d2(n, INF);
  d2[pos] = 0;
  que.push(pos);
  while (!que.empty()) {
    int cur = que.front();
    que.pop();
    for (auto nxt : g[cur]) {
      if (d2[nxt] != INF) continue;
      d2[nxt] = d2[cur] + 1;
      que.push(nxt);
    }
  }
  for (int i = 0; i < n; i++) {
    if (d[i] != d[pos] + d2[i]) continue;
    ret = max(ret, (d[u] - 1) / 2 + d2[i]);
  }
  cout << ret << endl;
}
