#include <bits/stdc++.h>
using namespace std;
namespace {
template <typename T>
std::ostream &operator<<(std::ostream &, const std::vector<T> &);
template <typename T>
std::ostream &operator<<(std::ostream &, const std::deque<T> &);
template <typename T>
std::ostream &operator<<(std::ostream &, const std::set<T> &);
template <typename T>
std::ostream &operator<<(std::ostream &, const std::stack<T> &);
template <typename T>
std::ostream &operator<<(std::ostream &, const std::queue<T> &);
template <typename T>
std::ostream &operator<<(std::ostream &, const std::priority_queue<T> &);
template <typename T>
std::ostream &operator<<(std::ostream &, const std::unordered_set<T> &);
template <typename T, typename U>
std::ostream &operator<<(std::ostream &, const std::map<T, U> &);
template <typename T, typename U>
std::ostream &operator<<(std::ostream &, const std::unordered_map<T, U> &);
template <typename T, typename U>
std::ostream &operator<<(std::ostream &, const std::pair<T, U> &);
template <typename... T>
std::ostream &operator<<(std::ostream &, const std::tuple<T...> &);
template <typename T, std::size_t N>
std::ostream &operator<<(std::ostream &, const std::array<T, N> &);
template <typename Tuple, std::size_t N>
struct __TuplePrinter__ {
  static void print(std::ostream &os, const Tuple &t) {
    __TuplePrinter__<Tuple, N - 1>::print(os, t);
    os << ", " << std::get<N - 1>(t);
  }
};
template <typename Tuple>
struct __TuplePrinter__<Tuple, 1> {
  static void print(std::ostream &os, const Tuple &t) { os << std::get<0>(t); }
};
template <typename... T>
std::ostream &operator<<(std::ostream &os, const std::tuple<T...> &t) {
  os << '(';
  __TuplePrinter__<decltype(t), sizeof...(T)>::print(os, t);
  os << ')';
  return os;
}
template <typename T, typename U>
std::ostream &operator<<(std::ostream &os, const std::pair<T, U> &v) {
  return os << '(' << v.first << ", " << v.second << ')';
}
template <typename T, std::size_t N>
std::ostream &operator<<(std::ostream &os, const std::array<T, N> &c) {
  os << '[';
  for (auto it = begin(c); it != end(c);) {
    os << *it;
    os << (++it != end(c) ? ", " : "");
  }
  return os << ']';
}
template <typename T>
std::ostream &operator<<(std::ostream &os, const std::vector<T> &c) {
  os << '[';
  for (auto it = begin(c); it != end(c);) {
    os << *it;
    os << (++it != end(c) ? ", " : "");
  }
  return os << ']';
}
template <typename T>
std::ostream &operator<<(std::ostream &os, const std::deque<T> &c) {
  os << '[';
  for (auto it = begin(c); it != end(c);) {
    os << *it;
    os << (++it != end(c) ? ", " : "");
  }
  return os << ']';
}
template <typename T>
std::ostream &operator<<(std::ostream &os, const std::set<T> &c) {
  os << '[';
  for (auto it = begin(c); it != end(c);) {
    os << *it;
    os << (++it != end(c) ? ", " : "");
  }
  return os << ']';
}
template <typename T>
std::ostream &operator<<(std::ostream &os, const std::stack<T> &c) {
  std::deque<T> v;
  for (auto d = c; !d.empty(); d.pop()) v.push_front(d.top());
  return os << v;
}
template <typename T>
std::ostream &operator<<(std::ostream &os, const std::queue<T> &c) {
  std::deque<T> v;
  for (auto d = c; !d.empty(); d.pop()) v.push_back(d.front());
  return os << v;
}
template <typename T>
std::ostream &operator<<(std::ostream &os, const std::priority_queue<T> &c) {
  std::deque<T> v;
  for (auto d = c; !d.empty(); d.pop()) v.push_front(d.top());
  return os << v;
}
template <typename T>
std::ostream &operator<<(std::ostream &os, const std::unordered_set<T> &c) {
  os << '[';
  for (auto it = begin(c); it != end(c);) {
    os << *it;
    os << (++it != end(c) ? ", " : "");
  }
  return os << ']';
}
template <typename T, typename U>
std::ostream &operator<<(std::ostream &os, const std::map<T, U> &c) {
  os << '[';
  for (auto it = begin(c); it != end(c);) {
    os << *it;
    os << (++it != end(c) ? ", " : "");
  }
  return os << ']';
}
template <typename T, typename U>
std::ostream &operator<<(std::ostream &os, const std::unordered_map<T, U> &c) {
  os << '[';
  for (auto it = begin(c); it != end(c);) {
    os << *it;
    os << (++it != end(c) ? ", " : "");
  }
  return os << ']';
}
}  // namespace
inline long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
vector<long long> g[100010];
long long ga[100010], cn[100010];
signed main() {
  long long n;
  cin >> n;
  long long u, v;
  cin >> u >> v;
  for (long long i = 0; i < n - 1; i++) {
    long long a, b;
    cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  queue<pair<long long, long long> > q;
  q.push({v, 0});
  ga[v] = -1;
  while (!q.empty()) {
    long long now = q.front().first;
    long long cost = q.front().second;
    q.pop();
    for (long long i = 0; i < g[now].size(); i++) {
      long long next = g[now][i];
      if (ga[next] != 0) continue;
      ga[next] = cost + 1;
      q.push({next, cost + 1});
    }
  }
  queue<pair<long long, long long> > q2;
  q2.push({u, 0});
  cn[u] = -1;
  long long ans = -1;
  while (!q2.empty()) {
    long long now = q2.front().first;
    long long cost = q2.front().second;
    q2.pop();
    ans = max(ans, (cost + ga[now]) / 2);
    for (long long i = 0; i < g[now].size(); i++) {
      long long next = g[now][i];
      if (cn[next] != 0) continue;
      if (cost + 1 >= ga[next]) continue;
      cn[next] = cost + 1;
      q2.push({next, cost + 1});
    }
  }
  cout << ans << endl;
  return 0;
}
