#include <bits/stdc++.h>
using namespace std;
typedef vector<vector<int>> vii;
template <class T, class U>
inline bool chmax(T &a, const U &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T, class U>
inline bool chmin(T &a, const U &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const long long infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;
template <typename T>
class Edge {
 public:
  int srch;
  int to;
  T cost;
  Edge(int t, T w) : srch(-1), to(t), cost(w) {}
  Edge(int src, int t, T w) : srch(src), to(t), cost(w) {}
};
template <typename T>
using W_Graph = vector<vector<Edge<T>>>;
using Graph = vector<vector<int>>;
template <typename T>
using Matrix = vector<vector<T>>;
int n;
signed main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int u, v;
  cin >> n >> u >> v;
  Graph tree(n);
  for (int i = 0; i < ((int)(n - 1)); i++) {
    int p, q;
    cin >> p >> q;
    p--;
    q--;
    tree[p].push_back(q);
    tree[q].push_back(p);
  }
  queue<int> que;
  vector<int> dist(n, -1);
  que.push(u);
  dist[u] = 0;
  while (!que.size()) {
    int p = que.front();
    que.pop();
    for (int np : tree[p]) {
      if (dist[np] != -1) continue;
      dist[np] = dist[p] + 1;
      que.emplace(np);
    }
  }
  int node = 0;
  for (int i = 0; i < ((int)(n)); i++) {
    if (chmax(dist[node], dist[i])) node = i;
  }
  int ans = *max_element((dist).begin(), (dist).end());
  queue<int> o;
  que = o;
  vector<int> d(n, -1);
  dist = d;
  que.push(v);
  dist[v] = 0;
  while (!que.size()) {
    int p = que.front();
    que.pop();
    for (int np : tree[p]) {
      if (dist[np] != -1) continue;
      dist[np] = dist[p] + 1;
      que.emplace(np);
    }
  }
  ans -= dist[node];
  if (ans <= 0) ans = 0;
  cout << ans << '\n';
}
