#include <bits/stdc++.h>
using namespace std;
signed main() {
  int n;
  vector<int> p[100001];
  cin >> n;
  int u, v;
  cin >> u >> v;
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    p[a].push_back(b);
    p[b].push_back(a);
  }
  int tak[100001] = {};
  for (int i = 0; i < 100001; i++) {
    tak[i] = 1000000000;
  }
  bool f[100001] = {};
  queue<pair<int, int> > q;
  q.push(pair<int, int>(u, 0));
  while (!q.empty()) {
    pair<int, int> pp = q.front();
    int t = pp.first;
    int sc = pp.second;
    q.pop();
    if (tak[t] <= sc) {
      continue;
    }
    tak[t] = sc;
    for (int i = 0; i < p[t].size(); i++) {
      q.push(pair<int, int>(p[t][i], sc + 1));
    }
  }
  int ao[100001] = {};
  q.push(pair<int, int>(v, 0));
  while (!q.empty()) {
    pair<int, int> pp = q.front();
    int t = pp.first;
    int sc = pp.second;
    q.pop();
    if (f[t]) continue;
    f[t] = true;
    ao[t] = sc;
    for (int i = 0; i < p[t].size(); i++) {
      q.push(pair<int, int>(p[t][i], sc + 1));
    }
  }
  q.push(pair<int, int>(u, 0));
  tak[u] = -1, ao[v] = -1;
  int maxt = p[u][0];
  while (!q.empty()) {
    pair<int, int> pp = q.front();
    int t = pp.first;
    int sc = pp.second;
    q.pop();
    if (sc > ao[t]) continue;
    if (t != u)
      if (ao[maxt] < ao[t]) {
        maxt = t;
      }
    if (sc == ao[t]) continue;
    for (int i = 0; i < p[t].size(); i++) {
      q.push(pair<int, int>(p[t][i], sc + 1));
    }
  }
  tak[u] = 0, ao[v] = 0;
  if (maxt == v) {
    cout << 0 << endl;
  } else if ((ao[maxt] - tak[maxt]) % 2) {
    cout << ao[maxt] - 1 << endl;
  } else {
    cout << ao[maxt] << endl;
  }
}
