#include <bits/stdc++.h>
using namespace std;
void dfs(vector<vector<int>>& G, int u, vector<int>& dist) {
  for (auto v : G[u]) {
    if (dist[v] != -1) continue;
    dist[v] = dist[u] + 1;
    dfs(G, v, dist);
  }
}
int dfs2(vector<vector<int>>& G, int u, vector<int>& distT,
         vector<int>& distA) {
  if (distA[u] <= distT[u]) {
    return (distA[u] + distT[u]) / 2;
  }
  int ret = distT[u];
  for (auto v : G[u]) {
    if (distT[v] != -1) continue;
    distT[v] = distT[u] + 1;
    ret = max(ret, dfs2(G, v, distT, distA));
  }
  return ret;
}
int main(void) {
  ios::sync_with_stdio(false);
  int N, u, v;
  cin >> N >> u >> v;
  --u, --v;
  vector<vector<int>> G(N);
  for (int i = 0; i < (N - 1); i++) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    G[a].emplace_back(b);
    G[b].emplace_back(a);
  }
  vector<int> distA(N, -1);
  distA[v] = 0;
  dfs(G, v, distA);
  vector<int> distT(N, -1);
  distT[u] = 0;
  int answer = dfs2(G, u, distT, distA);
  cout << answer << endl;
  return 0;
}
