#include <bits/stdc++.h>
using namespace std;
void dfs(int n, int p, vector<int>& dist, vector<vector<int>>& tree) {
  for (int m : tree[n]) {
    if (m == p) {
      continue;
    }
    dist[m] = dist[n] + 1;
    dfs(m, n, dist, tree);
  }
}
int main() {
  int N, u, v;
  cin >> N >> u >> v;
  u--;
  v--;
  vector<vector<int>> tree(N, vector<int>());
  for (int i = 0; i < N - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    tree[a].push_back(b);
    tree[b].push_back(a);
  }
  vector<int> da(N, 1e9), dt(N, 1e9);
  dt[u] = 0;
  dfs(u, -1, dt, tree);
  da[v] = 0;
  dfs(v, -1, da, tree);
  int goal = -1;
  for (int i = 0; i < N; i++) {
    if (dt[i] < da[i]) {
      if (goal == -1) {
        goal = i;
      } else {
        if (dt[goal] < dt[i]) {
          goal = i;
        }
      }
    }
  }
  int ans = dt[goal] + ((da[goal] - dt[goal]) - 1);
  cout << ans << endl;
}
