#include <bits/stdc++.h>
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 50;
template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
using namespace std;
template <typename A, typename B>
string to_string(pair<A, B> p);
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
string to_string(const string &s) { return '"' + s + '"'; }
string to_string(const char *s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
         to_string(get<2>(p)) + ")";
}
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
         to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
template <typename T>
struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template <typename T>
using Edges = vector<edge<T>>;
template <typename T>
using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template <typename T>
using Matrix = vector<vector<T>>;
vector<int> pre;
template <typename T>
vector<T> dijkstra(vector<vector<edge<T>>> &g, int s) {
  const auto INFTY = numeric_limits<T>::max();
  vector<T> dist(g.size(), INFTY);
  pre.resize(g.size(), -1);
  using P = pair<T, int>;
  priority_queue<P, vector<P>, greater<P>> pq;
  dist[s] = 0;
  pq.emplace(dist[s], s);
  while (!pq.empty()) {
    auto x = pq.top();
    pq.pop();
    int v = x.second;
    if (dist[v] < x.first) continue;
    for (auto e : g[v]) {
      if (dist[e.to] > dist[v] + e.cost) {
        pre[e.to] = v;
        dist[e.to] = dist[v] + e.cost;
        pq.emplace(dist[e.to], e.to);
      }
    }
  }
  return dist;
}
template <typename T>
vector<T> get_path(int t) {
  vector<T> path;
  for (; t != -1; t = pre[t]) {
    path.push_back(t);
  }
  reverse(path.begin(), path.end());
  return path;
}
void solve() {
  int n, u, v;
  cin >> n >> u >> v;
  u--;
  v--;
  WeightedGraph<int> g(n);
  int a, b;
  for (int i = (int)0; i < (int)n - 1; ++i) {
    cin >> a >> b;
    a--;
    b--;
    g[a].emplace_back(b, 1);
    g[b].emplace_back(a, 1);
  }
  int ans = 0;
  for (auto &x : dijkstra(g, v)) {
    chmax(ans, x);
  }
  cout << ans - 1 << "\n";
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(15);
  solve();
  return 0;
}
