#include <bits/stdc++.h>
using ll = long long;
using pii = std::pair<int, int>;
using vi = std::vector<int>;
using vvi = std::vector<vi>;
using vll = std::vector<ll>;
using vvll = std::vector<vll>;
using vd = std::vector<double>;
using vvd = std::vector<vd>;
using qi = std::queue<int>;
using vpii = std::vector<std::pair<int, int> >;
using namespace std;
const int Mod = (1e9) + 7;
const int max_n = 3 * (1e5) + 1;
const int max_m = 83 * (1e5) + 1;
const int INF = 10241024;
const ll INFL = (1ll << 62) - 1;
const int dx[] = {-1, 0, 0, 1};
const int dy[] = {0, -1, 1, 0};
template <class T1, class T2>
inline void chmin(T1 &a, T2 b) {
  if (a > b) a = b;
}
template <class T1, class T2>
inline void chmax(T1 &a, T2 b) {
  if (a < b) a = b;
}
template <class T1, class T2>
void update(T1 &a, T2 b) {
  a += b;
  if (a > Mod) a %= Mod;
}
inline void IN(void) { return; }
template <typename First, typename... Rest>
void IN(First &first, Rest &...rest) {
  cin >> first;
  IN(rest...);
  return;
}
inline void OUT(void) {
  cout << "\n";
  return;
}
template <typename First, typename... Rest>
void OUT(First first, Rest... rest) {
  cout << first << " ";
  OUT(rest...);
  return;
}
template <class T>
struct segt {
  int n;
  T def;
  vector<T> dat;
  function<T(T, T)> operation;
  function<T(T, T)> update;
  segt(size_t _n, T _def, function<T(T, T)> _operation,
       function<T(T, T)> _update)
      : def(_def), operation(_operation), update(_update) {
    n = 1;
    while (n < _n) {
      n *= 2;
    }
    dat = vector<T>(2 * n - 1, _def);
  }
  T _query(int a, int b, int k, int l, int r) {
    if (r <= a || b <= l) return def;
    if (a <= r && l <= b)
      return dat[k];
    else {
      T vl = _query(a, b, k * 2 + 1, l, (l + r) / 2);
      T vr = _query(a, b, k * 2 + 2, (l + r) / 2, r);
      return operation(vl, vr);
    }
  }
  T query(int a, int b) { return _query(a, b, 0, 0, n); }
  void change(int i, T value) {
    i += n - 1;
    dat[i] = update(dat[i], value);
    while (i > 0) {
      i = (i - 1) / 2;
      dat[i] = operation(dat[i * 2 + 1], dat[i * 2 + 2]);
    }
  }
  T operator[](int i) { return dat[i + n - 1]; }
};
int n, m, k, x, y;
vll dp(1 << 16, -1e18);
string s;
vvll v(16, vll(16));
vll cost(1 << 16);
vi dist;
vi dat[10005];
void dfs(int v, int u = -1, int score = 0) {
  dist[v] = score;
  for (auto c : dat[v]) {
    if (c == u) continue;
    dfs(c, v, score + 1);
  }
}
vi f(int x) {
  dist = vi(n);
  dfs(x);
  return dist;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int u, v;
  IN(n, u, v);
  u--;
  v--;
  for (int(i) = 0; (i) < (n - 1); (i)++) {
    int a, b;
    IN(a, b);
    a--;
    b--;
    dat[a].push_back(b);
    dat[b].push_back(a);
  }
  vi distU = f(u);
  vi distV = f(v);
  int mx = 0;
  for (int(i) = 0; (i) < (n); (i)++) {
    if (distV[i] > distU[i]) {
      chmax(mx, distV[i]);
    }
  }
  mx--;
  OUT(mx);
  return 0;
}
