#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const long long INF = (1 << 30) - 1;
const long long LLINF = (1LL << 60LL);
const long long MOD = 1000000007;
const long long mod = 998244353;
const long long MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
long long dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
struct Timer {
  chrono::system_clock::time_point start, end;
  Timer() { start = chrono::system_clock::now(); }
  ~Timer() {
    end = chrono::system_clock::now();
    auto msec =
        chrono::duration_cast<chrono::milliseconds>(end - start).count();
    cerr << "time : " << msec << " ms" << endl;
  }
};
struct edge {
  long long to, cost;
};
long long n;
vector<edge> G[100010];
vector<long long> prever;
long long d[100010];
void dijkstra(long long s) {
  priority_queue<pair<long long, long long>, vector<pair<long long, long long>>,
                 greater<pair<long long, long long>>>
      que;
  fill(d, d + n, LLINF);
  d[s] = 0;
  que.push(pair<long long, long long>(0, s));
  prever = vector<long long>(n, -1);
  while (!que.empty()) {
    pair<long long, long long> p = que.top();
    que.pop();
    long long v = p.second;
    if (d[v] < p.first) continue;
    for (long long i = 0; i < (long long)G[v].size(); i++) {
      edge e = G[v][i];
      if (d[e.to] > d[v] + e.cost) {
        d[e.to] = d[v] + e.cost;
        prever[e.to] = v;
        que.push(pair<int, int>(d[e.to], e.to));
      }
    }
  }
}
vector<long long> get_path(long long t) {
  vector<long long> path;
  for (; t != -1; t = prever[t]) {
    path.push_back(t);
  }
  reverse(path.begin(), path.end());
  return path;
}
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Timer TM;
  long long u, v;
  cin >> n >> u >> v;
  u--;
  v--;
  for (long long i = 0; i < n - 1; i++) {
    long long a, b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back({b, 1});
    G[b].push_back({a, 1});
  }
  dijkstra(v);
  vector<long long> path = get_path(u);
  long long m = d[u];
  for (long long i = 0; i < (long long)path.size() / 2 + (path.size() % 2 != 0);
       i++) {
    G[path[i]].clear();
    G[path[i]].push_back({path[i + 1], 1});
  }
  dijkstra(v);
  long long ans = 0;
  if (m == 1) {
    cout << 0 << endl;
    return 0;
  }
  for (long long i = 0; i < n; i++) {
    if (d[i] != LLINF) {
      if (m % 2 == 0) {
        chmax(ans, max(1ll, d[i] - 2));
      } else {
        chmax(ans, max(1ll, d[i] - 1));
      }
    }
  }
  cout << ans << endl;
  return 0;
}
