#include <bits/stdc++.h>
using namespace std;
constexpr long long inf = 1e9;
vector<long long> G[100000];
long long d[100000], n, p[100000], v, prv = -1;
void dfs(long long v) {
  for (long long i = 0; i < G[v].size(); i++) {
    if (G[v][i] != p[v] && G[v][i] != prv) {
      d[G[v][i]] = d[v] + 1;
      p[G[v][i]] = v;
      dfs(G[v][i]);
    }
  }
}
void dist(long long v) {
  for (long long i = 0; i < n; i++) d[i] = inf;
  d[v] = 0, p[v] = -1;
  dfs(v);
}
signed main() {
  long long u, a, b;
  cin >> n >> u >> v;
  u--, v--;
  for (long long i = 0; i < n - 1; i++) {
    cin >> a >> b;
    a--, b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  dist(u);
  bool dvuo = d[v] % 2 == 1;
  long long mid, ans2 = 0;
  for (mid = v; d[mid] != (d[v] + 2) / 2; prv = mid, mid = p[mid], ans2++)
    ;
  dist(mid);
  long long ans = 0;
  for (long long i = 0; i < n; i++)
    if (d[i] != inf) ans = max(ans, d[i]);
  cout << ans + ans2 - 1 << endl;
}
