#include <bits/stdc++.h>
using namespace std;
template <typename T = long long>
inline T IN() {
  T x;
  cin >> x;
  return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&...tail) {
  cin >> head;
  CIN(move(tail)...);
}
template <typename T = string>
inline void eputs(T s) {
  cout << s << "\n";
  exit(0);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
  std::fill((T *)array, (T *)(array + N), val);
}
template <typename T>
using PQG = priority_queue<T, vector<T>, greater<T>>;
template <typename T>
using PQ = priority_queue<T>;
const long long INF = 1e9;
const long long MOD = 1e9 + 7;
const long long LINF = 1e18;
const double PI = atan(1.0) * 4.0;
const long long dw[] = {1, 1, 0, -1, -1, -1, 0, 1};
const long long dh[] = {0, 1, 1, 1, 0, -1, -1, -1};
long long dist[2][100100];
vector<vector<long long>> G;
void dfs(long long now, long long par, long long root, long long d) {
  dist[root][now] = d;
  for (auto &(to) : (G[now])) {
    if (to == par) continue;
    dfs(to, now, root, d + 1);
  }
}
signed main() {
  long long N, u, v;
  CIN(N, u, v);
  u--, v--;
  G.resize(N);
  for (long long i = 0; i < (N - 1); ++i) {
    long long A, B;
    CIN(A, B);
    A--, B--;
    G[A].emplace_back(B);
    G[B].emplace_back(A);
  }
  dfs(v, -1, 0, 0);
  dfs(u, -1, 1, 0);
  long long ans = 0;
  for (long long i = 0; i < (N); ++i) {
    if (dist[0][i] > dist[1][i]) {
      long long tmp = dist[0][i], tmp2 = dist[1][i];
      if (tmp % 2 != tmp2 % 2) tmp--;
      ans = max(ans, tmp);
    }
  }
  cout << ans << "\n";
}
