#include <bits/stdc++.h>
using namespace std;
const int N = 111111;
vector<int> graph[N];
int da[N], dt[N];
int pa, pt;
int n;
void dfs(int u, int p, bool tak) {
  if (p) {
    if (tak)
      dt[u] = dt[p] + 1;
    else
      da[u] = da[p] + 1;
  }
  for (auto v : graph[u]) {
    if (v != p) {
      dfs(v, u, tak);
    }
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> pt >> pa;
  for (int i = (1); i <= (n - 1); i++) {
    int u, v;
    cin >> u >> v;
    graph[u].push_back(v);
    graph[v].push_back(u);
  }
  dfs(pa, 0, 0);
  dfs(pt, 0, 1);
  int ans = -1;
  for (int u = (1); u <= (n); u++) {
    if (da[u] > dt[u]) {
      bool has = false;
      for (auto v : graph[u]) {
        if (da[v] > dt[v]) {
          has = true;
          break;
        }
      }
      int rem = da[u] - dt[u];
      int cda = da[u];
      if (rem & 1)
        cda--;
      else if (rem && !has)
        cda--;
      if (cda > ans) {
        ans = cda;
      }
    }
  }
  cout << ans << "\n";
  return 0;
}
