#include <bits/stdc++.h>
using namespace std;
template <typename T>
using V = vector<T>;
using VL = V<long long>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<long long, long long>;
using VPL = V<PL>;
template <typename T>
inline bool chmax(T& a, T b);
template <typename T>
inline bool chmin(T& a, T b);
void print_ints(vector<long long> v);
template <typename T>
void drop(T a);
const long long INF = 1e18;
bool fill_path(long long u, long long p, long long goal, VL& path,
               VVL& edge_list) {
  if (p >= 0 && edge_list[u].size() == 1 && u != goal) return false;
  path.push_back(u);
  if (u == goal) return true;
  bool exist = false;
  for (auto v : edge_list[u]) {
    if (v == p) continue;
    if (fill_path(v, u, goal, path, edge_list)) {
      exist = true;
      break;
    }
  }
  if (!exist) path.pop_back();
  return exist;
}
long long N, tU, aV;
VVL edge_list;
long long limit_v, ng_v;
VVL ds;
long long dfs(long long u, long long p) {
  long long res = ds[aV][u] - 1;
  for (long long v : edge_list[u]) {
    if (v == ng_v || v == p) continue;
    long long _res = dfs(v, u);
    chmax(res, _res);
  }
  return res;
}
void solve() {
  cin >> N >> tU >> aV;
  tU--, aV--;
  if (tU == aV) drop(0);
  edge_list = VVL(N, VL(0));
  for (long long i = 0; i < (N - 1); ++i) {
    long long a, b;
    cin >> a >> b;
    a--, b--;
    edge_list[a].push_back(b);
    edge_list[b].push_back(a);
  }
  ds = VVL(N, VL(N, INF));
  for (long long from = 0; from < (N); ++from) {
    ds[from][from] = 0;
    for (long long to : edge_list[from]) {
      ds[from][to] = 1;
    }
  }
  for (long long k = 0; k < (N); ++k)
    for (long long i = 0; i < (N); ++i)
      for (long long j = 0; j < (N); ++j) {
        ds[i][j] = min(ds[i][j], ds[i][k] + ds[k][j]);
      }
  VL path(0);
  fill_path(tU, -1, aV, path, edge_list);
  limit_v = path[path.size() / 2 - 1];
  ng_v = path[path.size() / 2];
  long long res = dfs(limit_v, -1);
  cout << res << endl;
}
struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  try {
    solve();
  } catch (exit_exception& e) {
  }
  return 0;
}
template <typename T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
void print_ints(vector<long long> v) {
  for (long long i = 0; i < (v.size()); ++i) {
    if (i > 0) {
      cout << " ";
    }
    cout << v[i];
  }
  cout << endl;
}
template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}
