#include <bits/stdc++.h>
using namespace std;
vector<int> to[100005];
int n;
vector<int> dist(n);
void dfs(int s, int d = 0, int p = -1) {
  dist[s] = d;
  for (int u : to[s]) {
    if (u == p) continue;
    dfs(u, d + 1, s);
  }
}
vector<int> calcDist(int s) {
  dist = vector<int>(n);
  dfs(s);
  return dist;
}
int main() {
  int s, t;
  cin >> n >> s >> t;
  --s, --t;
  for (int i = (0); i < (n - 1); ++i) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  vector<int> distS = calcDist(s);
  vector<int> distT = calcDist(t);
  int mx = 0;
  for (int i = (0); i < (n); ++i) {
    if (distS[i] < distT[i]) {
      mx = distT[i];
    }
  }
  int ans = mx - 1;
  cout << ans << endl;
}
