#include <cstdio>
#include <cstdint>
#include <cassert>
#include <vector>
#include <algorithm>
#include <utility>
#include <numeric>
#include <functional>
#include <tuple>

constexpr intmax_t  operator ""_jd(unsigned long long n) { return n; }
constexpr uintmax_t operator ""_ju(unsigned long long n) { return n; }
constexpr size_t    operator ""_zu(unsigned long long n) { return n; }
// constexpr ptrdiff_t operator ""_td(unsigned long long n) { return n; }

template <typename F>
class fix_point: F {
public:
  explicit constexpr fix_point(F&& f) noexcept: F(std::forward<F>(f)) {}

  template <typename... Args>
  constexpr decltype(auto) operator ()(Args&&... args) const {
    return F::operator ()(*this, std::forward<Args>(args)...);
  }
};

template <typename F>
static inline constexpr decltype(auto) make_fix_point(F&& f) noexcept {
  return fix_point<F>{std::forward<F>(f)};
}

template <typename WeightType>
class weighted_edge {
public:
  using size_type = size_t;
  using weight_type = WeightType;

protected:
  size_type M_src, M_dst;
  weight_type M_weight;

public:
  weighted_edge() = default;
  weighted_edge(weighted_edge const&) = default;
  weighted_edge(weighted_edge&&) = default;

  weighted_edge(size_type s, size_type d, weight_type w):
    M_src(s), M_dst(d), M_weight(w)
  {}

  weighted_edge& operator =(weighted_edge const&) = default;
  weighted_edge& operator =(weighted_edge&&) = default;

  bool operator <(weighted_edge const& other) const {
    if (M_weight < other.M_weight) return true;
    if (other.M_weight < M_weight) return false;
    if (M_src != other.M_src) return M_src < other.M_src;
    return M_dst < other.M_dst;
  }

  size_type source() const { return M_src; }
  size_type target() const { return M_dst; }
  weight_type weight() const { return M_weight; }
};

struct directed_tag {};
struct undirected_tag {};

template <typename Edge, typename Directedness>
class adjacency_list {
public:
  using size_type = size_t;
  using edge_type = Edge;
  using weight_type = typename Edge::weight_type;
  static constexpr weight_type inf = std::numeric_limits<weight_type>::max();

private:
  std::vector<std::vector<edge_type>> M_g;

public:
  adjacency_list() = default;
  adjacency_list(adjacency_list const&) = default;
  adjacency_list(adjacency_list&&) = default;
  adjacency_list(size_type n): M_g(n) {}

  template <typename... Args>
  void emplace(size_type src, size_type dst, Args... args) {
    M_g[src].emplace_back(src, dst, args...);
    if (std::is_same<Directedness, undirected_tag>::value)
      M_g[dst].emplace_back(dst, src, args...);
  }

  void sort_by_index() {
    auto cmp = [](auto const& e1, auto const& e2) {
      return e1.target() < e2.target();
    };
    for (auto v: M_g) std::sort(v.begin(), v.end(), cmp);
  }

  size_type size() const { return M_g.size(); }
  std::vector<edge_type> const& operator [](size_type i) const { return M_g[i]; }
};

template <typename Edge, typename Directedness>
constexpr typename Edge::weight_type inf = adjacency_list<Edge, Directedness>::inf;

template <class Tp, class Compare = std::less<Tp>>
class sparse_table {
public:
  using size_type = size_t;
  using value_type = Tp;
  using value_compare = Compare;

private:
  std::vector<std::vector<value_type>> c;
  value_compare comp;

public:
  sparse_table() = default;
  sparse_table(sparse_table const&) = default;
  sparse_table(sparse_table&&) = default;

  template <class InputIt>
  sparse_table(InputIt first, InputIt last,
               value_compare comp = value_compare()):
    c(1, std::vector<value_type>(first, last)), comp(comp)
  {
    size_type n = c[0].size();
    for (size_type i = 1, ii = 1; c.back().size() > ii; (++i, ii <<= 1)) {
      c.emplace_back();
      c.back().reserve(n - ii);
      for (size_type j = ii; j < c[i-1].size(); ++j)
        c[i].push_back(std::min(c[i-1][j], c[i-1][j-ii], comp));
    }
  }

  sparse_table& operator =(sparse_table const&) = default;
  sparse_table& operator =(sparse_table&&) = default;

  value_type get(size_type l, size_type r) const {
    assert(l < r);
    size_type e = 63 - __builtin_clzll(r-l);
    r -= (1_zu << e) - 1;
    return std::min(c[e][l], c[e][r-1], comp);
  }
};

class tree_lowest_common_ancestor {
public:
  using size_type = size_t;

private:
  std::vector<size_type> M_e;
  sparse_table<std::pair<size_type, size_type>> M_st;

  template <typename Graph>
  void M_dfs(Graph const& g, size_type v, size_type p, size_type d0,
             std::vector<std::pair<size_type, size_type>>& d) {

    M_e[v] = d.size();
    d.emplace_back(d0, v);
    for (auto const& e: g[v]) {
      if (e.target() == p) continue;
      M_dfs(g, e.target(), v, d0+1, d);
      d.emplace_back(d0, v);
    }
  }

public:
  tree_lowest_common_ancestor() = default;
  tree_lowest_common_ancestor(tree_lowest_common_ancestor const&) = default;
  tree_lowest_common_ancestor(tree_lowest_common_ancestor&&) = default;

  template <typename Graph>
  tree_lowest_common_ancestor(Graph const& g, size_type r): M_e(g.size()) {
    std::vector<std::pair<size_type, size_type>> d;
    M_dfs(g, r, -1, 0, d);
    M_st = sparse_table<std::pair<size_type, size_type>>(d.begin(), d.end());
  }

  size_type operator ()(size_type u, size_type v) const {
    size_type x, y;
    std::tie(x, y) = std::minmax(M_e[u], M_e[v]);
    return M_st.get(x, y+1).second;
  }
};

template <typename Tree>
auto tree_distance(Tree const& g, size_t s) {
  using weight_type = typename Tree::weight_type;
  std::vector<weight_type> res(g.size());
  make_fix_point([&](auto dfs, size_t v, size_t p) -> void {
      for (auto const& e: g[v]) {
        size_t nv = e.target();
        if (nv == p) continue;
        res[nv] = res[v] + e.weight();
        dfs(nv, v);
      }
  })(s, -1);
  return res;
}

template <typename Tree>
auto tree_leaves(Tree const& g, size_t s) {
  std::vector<size_t> res;
  make_fix_point([&](auto dfs, size_t v, size_t p) -> void {
      bool has_child = false;
      for (auto const& e: g[v]) {
        size_t nv = e.target();
        if (nv == p) continue;
        has_child = true;
        dfs(nv, v);
      }
      if (!has_child) res.push_back(v);
  })(s, -1);
  return res;
}

int main() {
  size_t n, u, v;
  scanf("%zu %zu %zu", &n, &u, &v);
  --u, --v;

  adjacency_list<weighted_edge<int>, undirected_tag> g(n);
  for (size_t i = 1; i < n; ++i) {
    size_t a, b;
    scanf("%zu %zu", &a, &b);
    --a, --b;
    g.emplace(a, b, 1);
  }

  tree_lowest_common_ancestor lca(g, v);
  auto du = tree_distance(g, u);
  auto dv = tree_distance(g, v);

  intmax_t res = dv[u] / 2;
  for (size_t lf: tree_leaves(g, v)) {
    size_t w = lca(lf, u);
    if (dv[w] <= du[w]) continue;
    intmax_t cur = dv[lf]-1;
    res = std::max(res, cur);
  }
  printf("%jd\n", res);
}


Measured memory_bytes: 69300