#include <bits/stdc++.h>
using namespace std;
const long long inf = (long long)(1e17 + 17);
const long long mod = (long long)(1e9 + 7);
vector<vector<long long> > adj;
vector<long long> tin;
void dfs1(long long idx, long long parent, long long t) {
  tin[idx] = t;
  for (auto it : adj[idx]) {
    if (it == parent) continue;
    dfs1(it, idx, t + 1);
  }
}
long long ans = 0;
void dfs(long long idx, long long parent, long long t) {
  if (t <= tin[idx]) ans = max(ans, t % 2 ? t : t - 1);
  if (t > 0 and t <= tin[idx]) ans = max(ans, tin[idx] - 1 + (tin[idx] - t));
  for (auto it : adj[idx]) {
    if (it == parent) continue;
    dfs(it, idx, t + 1);
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, u, v;
  cin >> n >> u >> v;
  adj.resize(n + 1), tin.resize(n + 1, 0);
  for (long long i = 0; i < n - 1; i++) {
    long long x, y;
    cin >> x >> y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  dfs1(v, -1, 0);
  dfs(u, -1, 0);
  cout << ans << "\n";
  return 0;
}
