#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
constexpr int DEBUG = 0;
struct Edge {
  const int from, to;
  Edge(int from, int to) : from(from), to(to) {}
};
vector<vector<Edge>> ReadUndirectedGraph(int n, int m,
                                         bool is_one_indexed = false) {
  vector<vector<Edge>> graph(n);
  for (int i = 0; i < m; i++) {
    int v1, v2;
    cin >> v1 >> v2;
    if (is_one_indexed) {
      v1--;
      v2--;
    }
    graph[v1].push_back(Edge(v1, v2));
    graph[v2].push_back(Edge(v2, v1));
  }
  return graph;
}
template <class T>
inline bool UpdateMin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool UpdateMax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, u, v;
  cin >> n >> u >> v;
  u--;
  v--;
  auto graph = ReadUndirectedGraph(n, n - 1, true);
  vector<int> v_dists(n, -1);
  function<void(int, int)> dfs_1_fn = [&](int v, int p) {
    if (p < 0)
      v_dists[v] = 0;
    else
      v_dists[v] = v_dists[p] + 1;
    for (const auto& e : graph[v]) {
      if (e.to == p) continue;
      dfs_1_fn(e.to, v);
    }
  };
  dfs_1_fn(v, -1);
  vector<int> u_dists(n, -1);
  int ans = 0;
  function<void(int, int)> dfs_2_fn = [&](int v, int p) {
    if (p < 0) u_dists[v] = 0;
    if (u_dists[v] >= v_dists[v]) return;
    UpdateMax(ans, v_dists[v] - 1);
    for (const auto& e : graph[v]) {
      if (e.to == p) continue;
      dfs_2_fn(e.to, v);
    }
  };
  dfs_2_fn(u, -1);
  cout << ans << endl;
}
