#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
inline void chmin(T1 &a, T2 b) {
  if (a > b) a = b;
}
template <typename T1, typename T2>
inline void chmax(T1 &a, T2 b) {
  if (a < b) a = b;
}
int main() {
  int n, u, v;
  cin >> n >> u >> v;
  u--;
  v--;
  vector<vector<int>> to(n);
  for (int i = 0; i < (n - 1); i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  int rank[n];
  rank[v] = 0;
  bool vis[n];
  for (int i = 0; i < (n); i++) vis[i] = 0;
  queue<int> q;
  q.push(v);
  vis[v] = 1;
  while (!q.empty()) {
    int d = q.front();
    q.pop();
    for (auto p : to[d]) {
      if (!vis[p]) {
        vis[p] = 1;
        q.push(p);
        rank[p] = rank[d] + 1;
      }
    }
  }
  for (int i = 0; i < (n); i++) vis[i] = 0;
  vis[u] = 1;
  int dist[n];
  dist[u] = 0;
  while (!q.empty()) {
    int d = q.front();
    q.pop();
    for (auto p : to[d]) {
      if (!vis[p]) {
        vis[p] = 1;
        q.push(p);
        dist[p] = dist[u] + 1;
      }
    }
  }
  int ans = 0;
  if (rank[u] == 1) {
    cout << 1 << endl;
    return 0;
  }
  for (int i = 0; i < (n); i++) {
    if (dist[i] < rank[i]) ans = max(ans, rank[i] - 1);
  }
  cout << ans << endl;
}
