#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, u, v, a, b, i, dis = 0;
  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_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;
        q.push(mp[now][i]);
      }
    }
  }
  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_taka[mp[now][i]] > d_aoki[now] + 1) {
        d_aoki[mp[now][i]] = d_aoki[now] + 1;
        q.push(mp[now][i]);
        dis = max(dis, d_aoki[mp[now][i]]);
      }
    }
  }
  cout << dis + d_taka[v] - d_taka[v] % 2 - 1;
  return 0;
}
