#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
vector<int> v[maxn];
int disa[maxn], disb[maxn];
int bfs(int n, int a, int b) {
  memset(disb, -1, sizeof(disb));
  queue<int> q;
  q.push(b);
  disb[b] = 0;
  while (!q.empty()) {
    int cur = q.front();
    q.pop();
    for (int i = 0; i < v[cur].size(); i++) {
      int tmp = v[cur][i];
      if (disb[tmp] == -1) {
        disb[tmp] = disb[cur] + 1;
        q.push(tmp);
      }
    }
  }
  memset(disa, -1, sizeof(disa));
  q.push(a);
  disa[a] = 0;
  int ans = 0;
  while (!q.empty()) {
    int cur = q.front();
    q.pop();
    for (int i = 0; i < v[cur].size(); i++) {
      int tmp = v[cur][i];
      if (disa[cur] + 1 < disb[tmp]) {
        q.push(tmp);
        disa[tmp] = max(disa[tmp], disa[cur] + 1);
        ans = max(ans, disa[tmp]);
      } else if (disb[tmp] == 1) {
        ans = max(ans, 1);
      }
    }
  }
  return ans;
}
int main() {
  int n, a, b;
  scanf("%d %d %d", &n, &a, &b);
  int x, y;
  bool flag = false;
  for (int i = 1; i < n; i++) {
    scanf("%d %d", &x, &y);
    v[x].push_back(y);
    v[y].push_back(x);
    if ((x == a && y == b) || (x == b && y == a)) {
      flag = true;
    }
  }
  if (flag) {
    cout << "0" << endl;
  } else {
    cout << bfs(n, a, b) << endl;
  }
  return 0;
}
