#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int taka, ao;
  cin >> taka >> ao;
  taka--;
  ao--;
  vector<vector<int>> mm(n);
  for (int i = 0; i < n - 1; ++i) {
    int foo, fooo;
    cin >> foo >> fooo;
    foo--;
    fooo--;
    mm[foo].push_back(fooo);
    mm[fooo].push_back(foo);
  }
  vector<int> aocost(n, -1), takacost(n, -1);
  queue<int> Q;
  Q.push(ao);
  aocost[ao] = 0;
  while (!Q.empty()) {
    int now = Q.front();
    Q.pop();
    int nowcost = aocost[now];
    for (int i = 0; i < mm[now].size(); ++i) {
      if (aocost[mm[now][i]] == -1) {
        Q.push(mm[now][i]);
        aocost[mm[now][i]] = aocost[now] + 1;
      }
    }
  }
  Q.push(taka);
  takacost[taka] = 0;
  int lastaocost = 0;
  while (!Q.empty()) {
    int now = Q.front();
    Q.pop();
    int nowcost = takacost[now];
    lastaocost = aocost[now];
    for (int i = 0; i < mm[now].size(); ++i) {
      if (takacost[mm[now][i]] == -1) {
        if (nowcost + 1 < aocost[mm[now][i]]) {
          Q.push(mm[now][i]);
          takacost[mm[now][i]] = takacost[now] + 1;
        }
      }
    }
  }
  cout << lastaocost - 1 << endl;
  return 0;
}
