#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

typedef boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000>> cpp_dec_float_1000;

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }
template<typename ... Args> std::string format(const std::string& fmt, Args ... args ) { size_t len = std::snprintf( nullptr, 0, fmt.c_str(), args ... ); std::vector<char> buf(len + 1); std::snprintf(&buf[0], len + 1, fmt.c_str(), args ... ); return std::string(&buf[0], &buf[0] + len); }


struct Tmp {
  int u, v, count;
  bool isTakahashi;
};

void solve(void)
{
  int N; cin >> N;
  int u, v; cin >> u >> v;
  --u, --v;
  vector<vector<int>> tree(N);
  for (int _ = 0; _ < N-1; ++_) {
    int a, b; cin >> a >> b;
    --a; --b;
    tree[a].push_back(b);
    tree[b].push_back(a);
  }

  vector<int> takahashi(N, -1);
  vector<int> aoki(N, -1);
  { // aoki
    std::queue<int> que{};
    que.push(v);
    aoki[v] = 0;
    while (!que.empty()) {
      auto c = que.front();
      que.pop();
      for (const auto& n : tree[c]) {
        if (aoki[n] == -1) {
          aoki[n] = aoki[c] + 1;
          que.push(n);
        }
      }
    }
  }

  int ans{-1};
  { // takahashi
    std::queue<int> que{};
    que.push(u);
    takahashi[u] = 0;
    while (!que.empty()) {
      auto c = que.front();
      que.pop();
      if (aoki[c] > takahashi[c]) {
        ans = aoki[c]-1;
      }
      else {
        continue;
      }
      for (const auto& n : tree[c]) {
        if (takahashi[n] == -1) {
          takahashi[n] = takahashi[c] + 1;
          que.push(n);
        }
      }
    }
  }
  assert(ans != -1);
  cout << ans << CRLF;
  return;
}

int main(void)
{
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);

  solve();

  return 0;
}
