#include <bits/stdc++.h>
long long INF = (1ll << 61);
using namespace std;
long long u, v, t;
vector<long long>* g;
long long dep[2][100005];
void dfs(int V, int pV, int h, int i) {
  dep[i][V] = h;
  for (auto k : g[V]) {
    if (k == pV) continue;
    dfs(k, V, h + 1, i);
  }
}
int main(int argc, char* argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n;
  cin >> n >> u >> v;
  g = new vector<long long>[n + 1];
  for (int i = 0; i < n - 1; i++) {
    long long a, b;
    cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  dfs(u, -1, 0, 0);
  dfs(v, -1, 0, 1);
  long long ans = 0;
  for (int i = 1; i < n + 1; i++) {
    if (int((g[i]).size()) == 1 && dep[0][i] <= dep[1][i]) {
      ans = max(ans, dep[0][i] - (dep[0][i] == dep[1][i]));
    }
  }
  cout << ans << endl;
  return 0;
}
