#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int h[N], e[N * 2], ne[N * 2], idx;
int distu[N];
int distv[N];
int n, u, v;
int degree[N];
bool st1[N], st2[N];
void add(int a, int b) {
  e[idx] = b;
  ne[idx] = h[a];
  h[a] = idx++;
}
void bfsu() {
  vector<int> q;
  q.push_back(u);
  vector<int> temp;
  int cnt = 0;
  while (!q.empty()) {
    temp.clear();
    for (auto i : q) {
      if (!st1[i]) {
        st1[i] = true;
        distu[i] = cnt;
        for (int j = h[i]; j != -1; j = ne[j]) {
          int point = e[j];
          temp.push_back(point);
        }
      }
    }
    cnt++;
    q = temp;
  }
}
void bfsv() {
  vector<int> q;
  q.push_back(v);
  vector<int> temp;
  int cnt = 0;
  while (!q.empty()) {
    temp.clear();
    for (auto i : q) {
      if (!st2[i]) {
        st2[i] = true;
        distv[i] = cnt;
        for (int j = h[i]; j != -1; j = ne[j]) {
          int point = e[j];
          temp.push_back(point);
        }
      }
    }
    cnt++;
    q = temp;
  }
}
int main() {
  cin >> n >> u >> v;
  idx++;
  memset(h, -1, sizeof h);
  for (int i = 1; i < n; i++) {
    int a, b;
    cin >> a >> b;
    add(a, b);
    add(b, a);
    degree[a]++;
    degree[b]++;
  }
  bfsu();
  bfsv();
  int res = 0;
  for (int i = 1; i <= n; i++) {
    if (degree[i] == 1 && distu[i] > distv[i]) res = max(res, distu[i] - 1);
  }
  cout << res << endl;
  return 0;
}
