#include <bits/stdc++.h>
using namespace std;
void preprocess(void) { return; }
vector<vector<int> > adj;
void dfs(int v, int par, vector<int>& d) {
  if (par != -1) {
    d[v] = d[par] + 1;
  }
  for (auto x : adj[v]) {
    if (x == par) continue;
    dfs(x, v, d);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.precision(20);
  preprocess();
  int n, u, v;
  cin >> n >> u >> v;
  adj.resize(n + 1, vector<int>(0));
  for (auto i = (0); i < n - 1; i++) {
    int x, y;
    cin >> x >> y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  vector<int> d1(n + 1), d2(n + 1);
  dfs(u, -1, d1);
  dfs(v, -1, d2);
  int ans = 0;
  int m = -1;
  for (auto i = (1); i < n + 1; i++) {
    if (d1[i] < d2[i]) {
      int s = 0;
      if (d1[i] % 2 != d2[i] % 2) {
        s = 2 * (d2[i] - 1);
      } else {
        s = d2[i] - 1 + d2[i];
      }
      if (s > m) {
        s = m;
        ans = d2[i] - 1;
      }
    }
  }
  cout << ans << endl;
}
