#include <bits/stdc++.h>
using namespace std;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
struct edge {
  long long to, cost;
};
long long N;
vector<edge> G[100010];
long long d[2][100010];
void dikstra(long long s, long long a) {
  priority_queue<pair<long long, long long>,
                 vector<pair<long long, long long> >,
                 greater<pair<long long, long long> > >
      que;
  for (long long i = 0; i < N; i++) d[a][i] = 1000000000;
  d[a][s] = 0;
  que.push(pair<long long, long long>(0, s));
  while (!que.empty()) {
    pair<long long, long long> p = que.top();
    que.pop();
    long long v = p.second;
    if (d[a][v] < p.first) continue;
    for (long long i = 0; i < G[v].size(); i++) {
      edge e = G[v][i];
      if (d[a][e.to] > d[a][v] + e.cost) {
        d[a][e.to] = d[a][v] + e.cost;
        que.push(pair<long long, long long>(d[a][e.to], e.to));
      }
    }
  }
}
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> N;
  long long u, v;
  cin >> u >> v;
  u--;
  v--;
  for (long long i = 0; i < N - 1; i++) {
    long long a, b;
    cin >> a >> b;
    a--;
    b--;
    edge e;
    e.to = b;
    e.cost = 1;
    G[a].push_back(e);
    e.to = a;
    G[b].push_back(e);
  }
  dikstra(u, 0);
  dikstra(v, 1);
  long long ans = 0;
  long long anss = 1000000000;
  queue<long long> Q;
  Q.push(u);
  vector<bool> vis(N, false);
  while (!Q.empty()) {
    long long a = Q.front();
    Q.pop();
    vis[a] = true;
    chmax(ans, (d[0][a] + d[1][a]) / 2);
    for (long long i = 0; i < G[a].size(); i++) {
      if (!vis[G[a][i].to] && d[1][a] > d[0][a]) {
        Q.push(G[a][i].to);
      }
    }
  }
  cout << ans << endl;
  return 0;
}
