#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
vector<vector<int>> to(100000);
vector<int> pa(100000, -1);
vector<int> d(100000, 0);
int dfs(int v, int dist = 0, int p = -1) {
  pa[v] = p;
  int ret = dist;
  for (int t : to[v]) {
    if (t == p) continue;
    ret = max(ret, dfs(t, dist + 1, v));
  }
  d[v] = ret;
  return ret;
}
int main() {
  int n, u, v;
  cin >> n >> u >> v;
  u--;
  v--;
  for (int i = 0; i < (n - 1); ++i) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  dfs(v);
  int cnt = 0;
  int idx = pa[u];
  while (idx != v) {
    idx = pa[idx];
    cnt++;
  }
  int ans = d[u];
  idx = pa[u];
  for (int i = 0; i < (cnt / 2); ++i) {
    idx = pa[idx];
    ans = max(ans, d[idx]);
  }
  cout << ans - 1 << endl;
}
