#include <bits/stdc++.h>
using namespace std;
struct nd {
  vector<int> ady;
} G[100010];
int n, u, v, d[100010][2], a, b, f[100010][2], currentNode, ans, maxD;
bool vis[100010][2];
void dfs(int node, int band, int dist) {
  vis[node][band] = true;
  d[node][band] = dist;
  for (auto sig : G[node].ady)
    if (!vis[sig][band]) {
      dfs(sig, band, dist + 1);
      f[sig][band] = node;
    }
  return;
}
void dfs2(int node, int ant, int dist) {
  maxD = max(maxD, dist);
  for (auto sig : G[node].ady)
    if (sig != ant) dfs2(sig, node, dist + 1);
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> u >> v;
  swap(u, v);
  for (int i = 1; i < n; i++)
    cin >> a >> b, G[a].ady.push_back(b), G[b].ady.push_back(a);
  dfs(u, 0, 0);
  dfs(v, 1, 0);
  f[u][0] = u;
  f[v][1] = v;
  currentNode = v;
  while (d[f[currentNode][0]][0] > d[f[currentNode][0]][1])
    currentNode = f[currentNode][0], ans++;
  dfs2(currentNode, f[currentNode][0], 0);
  if (f[currentNode][0] != u) {
    ans = ans + max(1, maxD);
  } else {
    ans += maxD;
  }
  cout << ans;
  return 0;
}
