#include <bits/stdc++.h>
using namespace std;
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (T &x : vec) is >> x;
  return is;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &pair_var) {
  os << "(" << pair_var.first << ", " << pair_var.second << ")";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "{";
  for (int i = 0; i < vec.size(); i++) {
    os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
  }
  os << "}\n   ";
  return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, map<T, U> &map_var) {
  os << "{";
  for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
    os << *itr;
    itr++;
    if (itr != map_var.end()) os << ", ";
    itr--;
  }
  os << "}";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, set<T> &set_var) {
  os << "{";
  for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
    os << *itr;
    itr++;
    if (itr != set_var.end()) os << ", ";
    itr--;
  }
  os << "}";
  return os;
}
void dump_func() { cerr << endl; }
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&...tail) {
  cerr << head;
  if (sizeof...(Tail) > 0) {
    cerr << ", ";
  }
  dump_func(std::move(tail)...);
}
vector<int> ud;
vector<int> vd;
vector<vector<int>> tree;
void dfs(int n, int prev, int depth, bool flag) {
  if (flag) {
    ud[n] = depth;
  } else {
    vd[n] = depth;
  }
  for (auto next : tree[n]) {
    if (next != prev) {
      dfs(next, n, depth + 1, flag);
    }
  };
}
int main() {
  int N, u, v;
  cin >> N >> u >> v;
  u--;
  v--;
  tree = vector<vector<int>>(N, vector<int>());
  ud = vector<int>(N);
  vd = vector<int>(N);
  for (int i = 0, i_len = (N - 1); i < i_len; ++i) {
    int A, B;
    cin >> A >> B;
    A--;
    B--;
    tree[A].push_back(B);
    tree[B].push_back(A);
  }
  dfs(u, -1, 0, true);
  dfs(v, -1, 0, false);
  auto reachable = vector<int>();
  int far;
  int max_d = -1;
  for (int i = 0, i_len = (N); i < i_len; ++i) {
    if (ud[i] < vd[i]) {
      if (ud[i] > max_d) {
        far = i;
      }
    }
  }
  int sec_far = tree[far][0];
  cout << vd[sec_far] << endl;
}
