#include <bits/stdc++.h>
using namespace std;
const int LARGE_INT = 1000000007;
const long long LARGE_LONG = 1L << 62;
const int dx[] = {-1, -1, -1, 0, 0, 1, 1, 1},
          dy[] = {-1, 0, 1, -1, 1, -1, 0, 1};
int dfs(vector<vector<int> >& adj, vector<pair<int, int> >& pd, int parent,
        int x) {
  int maxh = 0;
  for (int y : adj[x]) {
    if (y != parent) maxh = max(maxh, dfs(adj, pd, x, y) + 1);
  }
  pd[x] = make_pair(parent, maxh);
  return maxh;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, a, b, u, v;
  cin >> n >> a >> b;
  a--;
  b--;
  vector<vector<int> > adj(n, vector<int>());
  vector<pair<int, int> > pd(n);
  for (int i = (int)(0); i < (int)(n - 1); i++) {
    cin >> u >> v;
    u--;
    v--;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  dfs(adj, pd, v, v);
  vector<int> path;
  int x = pd[u].first;
  while (x != v) {
    path.push_back(x);
    x = pd[x].first;
  }
  int ans = 0, cu = u, cv = v;
  auto it = path.end()--;
  while (true) {
    if (pd[cu].first == cv) {
      ans += pd[cu].second;
      break;
    } else if (pd[pd[cu].first].first == cv) {
      ans += pd[cu].second + 1;
      break;
    } else {
      ans++;
      cu = pd[cu].first;
      cv = *it;
      it--;
    }
  }
  cout << ans << endl;
  return 0;
}
