#include <bits/stdc++.h>
namespace tools {
template <typename T>
void read(::std::istream& is, ::std::vector<T>& vector,
          const typename ::std::vector<T>::size_type size) {
  vector.reserve(size);
  ::std::copy_n(::std::istream_iterator<T>(is), size,
                ::std::back_inserter(vector));
}
template <typename T>
void read(::std::vector<T>& vector,
          const typename ::std::vector<T>::size_type size) {
  ::tools::read(::std::cin, vector, size);
}
template <typename T, ::std::size_t N>
void read(::std::istream& is, ::std::array<T, N>& array) {
  ::std::copy_n(std::istream_iterator<T>(is), N, array.begin());
}
template <typename T, ::std::size_t N>
void read(::std::array<T, N>& array) {
  ::tools::read(::std::cin, array);
}
}  // namespace tools
int main() {
  ::std::int_fast64_t N, u, v;
  std::cin >> N >> u >> v;
  --u;
  --v;
  std::vector<std::vector<::std::int_fast64_t>> graph(N);
  for (::std::int_fast64_t i = 0; i < N - 1; ++i) {
    ::std::int_fast64_t A, B;
    std::cin >> A >> B;
    --A;
    --B;
    graph[A].push_back(B);
    graph[B].push_back(A);
  }
  const auto bfs = [&N, &graph](
                       const ::std::int_fast64_t& root,
                       const std::unordered_set<::std::int_fast64_t>& no_entry,
                       const std::function<void(::std::int_fast64_t,
                                                ::std::int_fast64_t)>& invoke) {
    std::queue<std::pair<::std::int_fast64_t, ::std::int_fast64_t>> queue(
        {std::make_pair(root, root)});
    std::vector<bool> planned_to_visit(N, false);
    planned_to_visit[root] = true;
    while (!queue.empty()) {
      const ::std::int_fast64_t prev = queue.front().first;
      const ::std::int_fast64_t curr = queue.front().second;
      queue.pop();
      invoke(prev, curr);
      for (const ::std::int_fast64_t& next : graph[curr]) {
        if (!planned_to_visit[next] && no_entry.find(next) == no_entry.end()) {
          queue.push(std::make_pair(curr, next));
          planned_to_visit[next] = true;
        }
      }
    }
  };
  std::vector<::std::int_fast64_t> for_takahashi(N), for_aoki(N),
      steps_to_takahashi(N), steps_to_aoki(N), steps_to_leaf(N);
  bfs(u, std::unordered_set<::std::int_fast64_t>(),
      [&for_takahashi, &steps_to_takahashi](const ::std::int_fast64_t& prev,
                                            const ::std::int_fast64_t& curr) {
        for_takahashi[curr] = prev;
        if (prev == curr) {
          steps_to_takahashi[curr] = 0;
        } else {
          steps_to_takahashi[curr] = steps_to_takahashi[prev] + 1;
        }
      });
  bfs(v, std::unordered_set<::std::int_fast64_t>(),
      [&for_aoki, &steps_to_aoki](const ::std::int_fast64_t& prev,
                                  const ::std::int_fast64_t& curr) {
        for_aoki[curr] = prev;
        if (prev == curr) {
          steps_to_aoki[curr] = 0;
        } else {
          steps_to_aoki[curr] = steps_to_aoki[prev] + 1;
        }
      });
  ::std::int_fast64_t takahashi_side_farthest = 0;
  {
    std::unordered_set<::std::int_fast64_t> no_entry;
    for (const ::std::int_fast64_t& next : graph[v]) {
      if (for_takahashi[next] != for_aoki[next]) {
        no_entry.insert(next);
      }
    }
    bfs(v, no_entry,
        [&graph, &steps_to_takahashi, &takahashi_side_farthest](
            const ::std::int_fast64_t& prev, const ::std::int_fast64_t& curr) {
          static_cast<void>(prev);
          if (graph[curr].size() == 1) {
            takahashi_side_farthest =
                std::max(takahashi_side_farthest, steps_to_takahashi[curr]);
          }
        });
  }
  ::std::int_fast64_t answer = steps_to_aoki[v] + takahashi_side_farthest - 1;
  {
    std::vector<::std::int_fast64_t> connection;
    for (::std::int_fast64_t i = 0; i < N; ++i) {
      if (i != for_takahashi[i] && i != for_aoki[i] &&
          for_takahashi[i] != for_aoki[i]) {
        connection.push_back(i);
      }
    }
    std::vector<::std::int_fast64_t> steps_to_root(N);
    for (const ::std::int_fast64_t& root : connection) {
      if (steps_to_takahashi[root] < steps_to_aoki[root]) {
        ::std::int_fast64_t farthest = 0;
        bfs(root,
            std::unordered_set<::std::int_fast64_t>(
                {for_takahashi[root], for_aoki[root]}),
            [&graph, &steps_to_root, &farthest](
                const ::std::int_fast64_t& prev,
                const ::std::int_fast64_t& curr) {
              if (prev == curr) {
                steps_to_root[curr] = 0;
              } else {
                steps_to_root[curr] = steps_to_root[prev] + 1;
                if (graph[curr].size() == 1) {
                  farthest = std::max(farthest, steps_to_root[curr]);
                }
              }
            });
        answer = std::max(answer, steps_to_aoki[root] + farthest - 1);
      }
    }
  }
  std::cout << answer << std::endl;
  return 0;
}
