#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef ::std::int_fast64_t i64;
typedef ::std::uint_fast64_t u64;
typedef ::std::int_fast32_t i32;
typedef ::std::uint_fast32_t u32;

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);
  }
}

#endif

// main.cpp

int main() {
  i64 N, u, v;
  std::cin >> N >> u >> v;
  --u;
  --v;
  std::vector<std::vector<i64>> graph(N);
  for (i64 i = 0; i < N - 1; ++i) {
    i64 A, B;
    std::cin >> A >> B;
    --A;
    --B;
    graph[A].push_back(B);
    graph[B].push_back(A);
  }

  const auto bfs = [&N, &graph](const i64& root, const std::unordered_set<i64>& no_entry, const std::function<void(i64, i64)>& invoke) {
    std::queue<std::pair<i64, i64>> queue({std::make_pair(root, root)});
    std::vector<bool> planned_to_visit(N, false);
    planned_to_visit[root] = true;

    while (!queue.empty()) {
      const i64 prev = queue.front().first;
      const i64 curr = queue.front().second;
      queue.pop();

      invoke(prev, curr);

      for (const i64& 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<i64> for_takahashi(N), for_aoki(N), steps_to_takahashi(N), steps_to_aoki(N), steps_to_leaf(N);
  bfs(u, std::unordered_set<i64>(), [&for_takahashi, &steps_to_takahashi](const i64& prev, const i64& 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<i64>(), [&for_aoki, &steps_to_aoki](const i64& prev, const i64& curr) {
    for_aoki[curr] = prev;
    if (prev == curr) {
      steps_to_aoki[curr] = 0;
    } else {
      steps_to_aoki[curr] = steps_to_aoki[prev] + 1;
    }
  });

  i64 takahashi_side_farthest = 0;
  {
    std::unordered_set<i64> no_entry;
    for (const i64& next : graph[u]) {
      if (for_takahashi[next] != for_aoki[next]) {
        no_entry.insert(next);
      }
    }
    bfs(u, no_entry, [&graph, &steps_to_takahashi, &takahashi_side_farthest](const i64& prev, const i64& curr) {
      static_cast<void>(prev);
      if (graph[curr].size() == 1) {
        takahashi_side_farthest = std::max(takahashi_side_farthest, steps_to_takahashi[curr]);
      }
    });
  }

  i64 answer = steps_to_aoki[u] + takahashi_side_farthest - 1;
  {
    std::vector<i64> connection;
    for (i64 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<i64> steps_to_root(N);
    for (const i64& root : connection) {
      if (steps_to_takahashi[root] < steps_to_aoki[root]) {
        i64 farthest = 0;

        bfs(root, std::unordered_set<i64>({for_takahashi[root], for_aoki[root]}), [&graph, &steps_to_root, &farthest](const i64& prev, const i64& 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;
}

Measured memory_bytes: 11208