#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> to[100005];
vector<int> dist;
void dfs(int a, int d = 0, int p = -1) {
  dist[a] = d;
  for (auto& c : to[a]) {
    if (c == p) continue;
    dfs(c, d + 1, a);
  }
}
vector<int> makedist(int a) {
  dist = vector<int>(n);
  dfs(a);
  return dist;
}
int main() {
  cin >> n;
  int u, v;
  cin >> u >> v;
  for (int i = 0; i < (n - 1); ++i) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    to[a].emplace_back(b);
    to[b].emplace_back(a);
  }
  vector<int> distT = makedist(u);
  vector<int> distA = makedist(v);
  int ans = 0;
  for (int i = 0; i < (n); ++i) {
    if (distT[i] < distA[i]) ans = max(ans, distA[i]);
  }
  cout << ans << endl;
  return 0;
}
