#include <bits/stdc++.h>
using namespace std;
using LL = long long;
constexpr int N = 1e5 + 5;
int dist[N];
vector<int> conn[N];
void dfs(int a, int prt, int d) {
  dist[a] = d;
  for (int& b : conn[a]) {
    if (b == prt) continue;
    dfs(b, a, d + 1);
  }
}
int dfs2(int a, int di) {
  int rv = -1;
  for (const int& b : conn[a]) {
    if (dist[b] == di or dist[b] == di + 1) {
      rv = max(rv, dist[b]);
    } else {
      rv = max(rv, dfs2(b, di + 1));
    }
  }
  return rv;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, u, v;
  cin >> n >> u >> v;
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    conn[a].push_back(b);
    conn[b].push_back(a);
  }
  dfs(v, v, 0);
  int result = dfs2(u, 0);
  cout << result << endl;
}
