#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, u, v, a, b, i, mem_v = -1, dis = -1;
  cin >> n >> u >> v;
  u--;
  v--;
  map<int, vector<int>> mp;
  queue<int> q;
  int d_taka[n], d_aoki[n];
  for (i = 0; i < n - 1; i++) {
    cin >> a >> b;
    mp[a - 1].push_back(b - 1);
    mp[b - 1].push_back(a - 1);
  }
  for (i = 0; i < n; i++) {
    d_taka[i] = 1000000000;
    d_aoki[i] = 1000000000;
  }
  d_aoki[v] = 0;
  q.push(v);
  while (!q.empty()) {
    int now = q.front();
    q.pop();
    for (i = 0; i < mp[now].size(); i++) {
      if (d_aoki[mp[now][i]] == 1000000000) {
        d_aoki[mp[now][i]] = d_aoki[now] + 1;
        q.push(mp[now][i]);
      }
    }
  }
  d_taka[u] = 0;
  q.push(u);
  while (!q.empty()) {
    int now = q.front();
    q.pop();
    for (i = 0; i < mp[now].size(); i++) {
      if (d_taka[mp[now][i]] == 1000000000) {
        d_taka[mp[now][i]] = d_taka[now] + 1;
        if (d_aoki[mp[now][i]] - d_taka[mp[now][i]] == 0 &&
            dis < d_aoki[mp[now][i]]) {
          dis = d_aoki[mp[now][i]];
          mem_v = mp[now][i];
        } else if (d_aoki[mp[now][i]] - d_taka[mp[now][i]] > 0) {
          if (dis < d_aoki[mp[now][i]]) {
            dis = d_aoki[mp[now][i]];
            mem_v = mp[now][i];
          }
          q.push(mp[now][i]);
        }
      }
    }
  }
  if (mem_v == -1 || d_aoki[u] == 0) {
    cout << 0 << "\n";
  } else {
    cout << d_aoki[mem_v] << "\n";
  }
  return 0;
}
