#include <bits/stdc++.h>
using namespace std;
const double PI = 3.141592653589;
template <class T>
void dbs(string str, T t) {
  cerr << str << " : " << t << "\n";
}
template <class T, class... S>
void dbs(string str, T t, S... s) {
  long long idx = str.find(',');
  cerr << str.substr(0, idx) << " : " << t << ", ";
  dbs(str.substr(idx + 1), s...);
}
template <class S, class T>
ostream& operator<<(ostream& os, const pair<S, T>& p) {
  return os << "(" << p.first << ", " << p.second << ")";
}
template <class T>
ostream& operator<<(ostream& os, const vector<T>& p) {
  os << "[ ";
  for (auto& it : p) os << it << " ";
  return os << "]";
}
template <class T>
ostream& operator<<(ostream& os, const set<T>& p) {
  os << "[ ";
  for (auto& it : p) os << it << " ";
  return os << "]";
}
template <class S, class T>
ostream& operator<<(ostream& os, const map<S, T>& p) {
  os << "[ ";
  for (auto& it : p) os << it << " ";
  return os << "]";
}
template <class T>
void prc(T a, T b) {
  cerr << "[";
  for (T i = a; i != b; ++i) {
    if (i != a) cerr << ", ";
    cerr << *i;
  }
  cerr << "]\n";
}
const long long N = (long long)1e5 + 5;
vector<long long> tree[N], lev(N, 0);
vector<bool> vis(N, false);
long long ans = 0;
long long n, x, y, dist = 0;
vector<bool> in_path(N, false);
bool dfs(long long node, long long curr = 0) {
  if (node == x) {
    dist = curr + 1;
    return true;
  }
  bool check = false;
  for (long long i : tree[node]) {
    if (vis[i]) continue;
    vis[i] = true;
    if (dfs(i, curr + 1)) check = true;
  }
  if (check) in_path[node] = true;
  return check;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> x >> y;
  for (long long i = 1; i < n; i++) {
    long long a, b;
    cin >> a >> b;
    tree[a].push_back(b);
    tree[b].push_back(a);
  }
  queue<long long> q;
  vis[y] = true;
  long long index = y;
  in_path[y] = true;
  for (long long i : tree[y]) {
    vis[i] = true;
    if (dfs(i)) {
      index = i;
      break;
    }
  }
  vis.assign(n + 1, false);
  lev.assign(n + 1, 0);
  long long curr = index;
  long long z = (dist) / 2, u = y, from = y;
  vis[y] = true;
  while (z > 0) {
    for (long long i : tree[u]) {
      if (i == from) continue;
      if (in_path[i]) {
        from = u;
        u = i;
        vis[u] = true;
        z--;
        break;
      }
    }
  }
  curr = u;
  lev[curr] = (dist) / 2;
  ans = 0;
  q.push(curr);
  vis[curr] = true;
  while (!q.empty()) {
    curr = q.front();
    q.pop();
    for (long long i : tree[curr]) {
      if (vis[i]) continue;
      vis[i] = true;
      lev[i] = lev[curr] + 1;
      ans = max(ans, lev[i]);
      q.push(i);
    }
  }
  cout << ans - 1 << "\n";
  return 0;
}
