#include <bits/stdc++.h>
using namespace std;
const int vx[4] = {0, 1, 0, -1};
const int vy[4] = {1, 0, -1, 0};
long long Madd(long long x, long long y) {
  return (x + y) % (long long)(1e9 + 7);
}
long long Msub(long long x, long long y) {
  return (x - y + (long long)(1e9 + 7)) % (long long)(1e9 + 7);
}
long long Mmul(long long x, long long y) {
  return (x * y) % (long long)(1e9 + 7);
}
template <typename T>
struct edge {
  long long src, to;
  T cost;
  edge(long long to, T cost) : src(-1), to(to), cost(cost) {}
  edge(long long src, long long to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const long long &x) {
    to = x;
    return *this;
  }
  operator long long() const { return to; }
};
template <typename T>
using Edges = vector<edge<T>>;
template <typename T>
using WG = vector<Edges<T>>;
using UG = vector<vector<long long>>;
template <typename T>
using Matrix = vector<vector<T>>;
template <typename T>
vector<T> dijkstra(WG<T> &g, long long s) {
  const auto lim = numeric_limits<T>::max();
  vector<T> dist(g.size(), lim);
  using Pi = pair<T, long long>;
  priority_queue<Pi, vector<Pi>, greater<Pi>> q;
  dist[s] = 0;
  q.emplace(dist[s], s);
  while (!q.empty()) {
    T cost;
    long long idx;
    tie(cost, idx) = q.top();
    q.pop();
    if (dist[idx] < cost) continue;
    for (auto &e : g[idx]) {
      auto next_cost = cost + e.cost;
      if (dist[e.to] <= next_cost) continue;
      dist[e.to] = next_cost;
      q.emplace(dist[e.to], e.to);
    }
  }
  return dist;
}
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  long long n, u, v;
  cin >> n >> u >> v;
  u--;
  v--;
  WG<long long> es(n);
  for (long long i = (long long)0; i < (long long)n - 1; i++) {
    long long a, b;
    cin >> a >> b;
    a--;
    b--;
    es[a].push_back(edge<long long>(b, 1));
    es[b].push_back(edge<long long>(a, 1));
  }
  vector<long long> distu = dijkstra(es, u);
  vector<long long> distv = dijkstra(es, v);
  long long ans = 0;
  for (long long i = (long long)0; i < (long long)n; i++) {
    ans = max(distu[i], distv[i]);
  }
  cout << ans - 1 << endl;
}
