#include <bits/stdc++.h>
using namespace std;
using uc = unsigned char;
using ui = unsigned int;
using ul = unsigned long long int;
using sc = signed char;
using si = signed int;
using sl = signed long long int;
using ld = long double;
void m_assert(const bool& cond, const sl& line, const char* condstr) {
  if (!cond) {
    cerr << "Assertion Failed: " << condstr << " at line " << line << endl;
    exit(1);
  }
}
template <class T>
struct DirectedEdge {
  sl to;
  T cost;
  DirectedEdge(const sl& _to, const T& _cost) : to(_to), cost(_cost) {}
};
template <class T>
struct Dijkstra {
  constexpr static sl INF = numeric_limits<T>::max() >> 1;
  vector<T> distance;
  vector<sl> prev;
  Dijkstra(const sl& N, const sl& start,
           const vector<vector<DirectedEdge<T>>>& edges) {
    priority_queue<pair<T, sl>, vector<pair<T, sl>>, greater<pair<T, sl>>> que;
    distance.resize(N);
    prev.resize(N);
    for (sl(i) = 0; (i) < (N); ++(i)) {
      if (i == start) {
        distance[start] = 0;
        prev[start] = start;
      } else {
        distance[i] = INF;
        prev[i] = numeric_limits<sl>::max();
      }
      que.emplace(distance[i], i);
    }
    while (!que.empty()) {
      auto u = que.top().second;
      que.pop();
      for (auto(it) = (edges[u]).begin(); (it) != (edges[u]).end(); (it)++) {
        sl v = it->to;
        T new_cost = distance[u] + it->cost;
        if (distance[v] > new_cost) {
          distance[v] = new_cost;
          prev[v] = u;
          que.emplace(new_cost, v);
        }
      }
    }
  }
};
static sl N, U, V;
vector<vector<DirectedEdge<sl>>> E;
void solve(void) {
  Dijkstra<sl> d(N, V, E);
  Dijkstra<sl> e(N, U, E);
  if (U == V || (E[U].size() == 1 && E[U][0].to == V)) {
    cout << 0 << endl;
    return;
  }
  sl max_cost = 0;
  for (sl(i) = 0; (i) < (N); ++(i)) {
    if (e.distance[i] != Dijkstra<sl>::INF) {
      if (d.distance[i] == Dijkstra<sl>::INF || d.distance[i] > e.distance[i]) {
        max_cost = max(max_cost, d.distance[i]) - 1;
      }
    }
  }
  cout << max_cost << endl;
}
int main(void) {
  cin >> N >> U >> V;
  U -= 1;
  V -= 1;
  E.resize(N);
  sl A, B;
  for (sl(i) = 0; (i) < (N - 1); ++(i)) {
    cin >> A >> B;
    A -= 1;
    B -= 1;
    E[A].emplace_back(B, 1);
    E[B].emplace_back(A, 1);
  }
  solve();
  return 0;
}
