#include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}
int main() {
  std::ios::sync_with_stdio(false);
  int n, u, v;
  cin >> n >> u >> v;
  u--;
  v--;
  vector<set<int>> edges(n);
  vector<int> dist_u(n, -1);
  vector<int> dist_v(n, -1);
  for (int i = 0; i < n - 1; ++i) {
    int a, b;
    cin >> a >> b;
    edges[a - 1].insert(b - 1);
    edges[b - 1].insert(a - 1);
  }
  int dist_u_v = 0;
  deque<pair<int, int>> q;
  q.push_back(make_pair(u, 0));
  while (!q.empty()) {
    int current = q.front().first;
    int dist = q.front().second;
    q.pop_front();
    dist_u[current] = dist;
    if (current == v) {
      dist_u_v = dist;
      continue;
    }
    for (const auto& nxt : edges[current]) {
      if (dist_u[nxt] == -1) q.push_back(make_pair(nxt, dist + 1));
    }
  }
  q.push_back(make_pair(v, 0));
  while (!q.empty()) {
    int current = q.front().first;
    int dist = q.front().second;
    q.pop_front();
    dist_v[current] = dist;
    for (const auto& nxt : edges[current]) {
      if (dist_v[nxt] == -1) q.push_back(make_pair(nxt, dist + 1));
    }
  }
  int cand = -1;
  for (int i = 0; i < n; ++i) {
    if (dist_u[i] < dist_v[i]) {
      cand = max(cand, dist_u[i]);
    }
  }
  cout << max(dist_u_v - 1, cand) << endl;
}
