#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
template <class T>
ostream& operator<<(ostream& os, vector<T>& _) {
  os << '{';
  for (T& x : _) {
    os << x;
    if (&x != &_.back()) os << ',';
  }
  os << '}';
  return os;
}
template <class T, class U>
ostream& operator<<(ostream& os, pair<T, U>& p) {
  return os << '{' << p.first << " " << p.second << '}';
}
template <class T>
class Dijkstra {
 public:
  Dijkstra(int node_size) : node_size_(node_size) { Initialize(); }
  void Add_Edge(int from, int to, T cost) {
    graph_[from].push_back({to, cost});
  }
  void Solve(int source) {
    std::priority_queue<std::pair<T, int>, std::vector<std::pair<T, int>>,
                        std::greater<std::pair<T, int>>>
        pq;
    distance_[source] = 0;
    pq.push({0, source});
    while (!pq.empty()) {
      std::pair<T, int> top = pq.top();
      pq.pop();
      int v = top.second;
      if (distance_[v] < top.first) continue;
      for (const auto& e : graph_[v]) {
        if (distance_[e.to] > distance_[v] + e.cost) {
          distance_[e.to] = distance_[v] + e.cost;
          pq.push({distance_[e.to], e.to});
        }
      }
    }
  }
  T operator[](int to) const { return distance_[to]; }

 private:
  struct edge {
    int to;
    T cost;
  };
  int node_size_;
  std::vector<T> distance_;
  std::vector<std::vector<edge>> graph_;
  void Initialize() {
    distance_.assign(node_size_, std::numeric_limits<T>::max() / 2);
    graph_.resize(node_size_);
  }
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, u, v;
  cin >> n >> u >> v;
  --u;
  --v;
  vector<vector<int>> graph(n);
  Dijkstra<int> dij_t(n);
  Dijkstra<int> dij_a(n);
  for (int i = 0; i < n - 1; ++i) {
    int a, b;
    cin >> a >> b;
    --a;
    --b;
    dij_t.Add_Edge(a, b, 1);
    dij_t.Add_Edge(b, a, 1);
    dij_a.Add_Edge(a, b, 1);
    dij_a.Add_Edge(b, a, 1);
  }
  dij_t.Solve(u);
  dij_a.Solve(v);
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    if (dij_t[i] < dij_a[i]) {
      ans = dij_a[i] - 1;
    }
  }
  cout << ans << endl;
  return 0;
}
