#include <bits/stdc++.h>
using namespace std;
const long long MAX1 = 2e5 + 7, MOD = 1e9 + 7;
long long n, flag, x, y, u, v, dis[3][MAX1], mark[MAX1], jav;
vector<long long> adj[MAX1];
void DFS(long long u, long long cnt) {
  mark[u] = 1;
  for (int i : adj[u]) {
    if (!mark[i]) dis[cnt][i] = dis[cnt][u] + 1, DFS(i, cnt);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n >> u >> v;
  for (int i = 0; i < n - 1; ++i) {
    cin >> x >> y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  DFS(v, 0);
  fill(mark, mark + MAX1, 0);
  DFS(u, 1);
  long long ans;
  x = 0;
  for (int i = 1; i <= n; ++i) {
    if (dis[0][i] > x) ans = i, x = dis[0][i];
  }
  for (int i = 1; i <= n; ++i) {
    if (dis[1][i] < dis[0][i]) {
      if (dis[0][i] < dis[0][ans]) ans = i, jav = dis[1][i];
    }
  }
  fill(mark, mark + MAX1, 0);
  DFS(ans, 2);
  ans = 0;
  long long marker;
  for (int i = 1; i <= n; ++i) {
    if (dis[2][i] < dis[0][i] + jav) {
      if (dis[2][i] > ans) ans = dis[2][i], marker = i;
    }
  }
  cout << jav + ans + 1 - ((ans + jav) % 2 == dis[2][marker] % 2);
  return 0;
}
