#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int n;
vector<int> t[100005];
vector<int> dist;

void walker(int c, int p, int d) {
  for(int n:t[c]) if(n!=p) walker(n, c, d+1);
  dist.at(c) = d;
}

vector<int> getDist(int pos) {
  dist = vector<int>(n);
  walker(pos, -1, 0);
  return dist;
}

int main() {
  int u, v, a, b, mx=0;
  cin >> n >> u >> v;
  for(int i=1;i<n;++i) {
    cin >> a >> b;
    --a; --b;
    t[a].push_back(b);
    t[b].push_back(a);
  }
  auto distU = getDist(--u);
  auto distV = getDist(--v);
  for(int i=0;i<n;++i) if(distU[i] < distV[i]) mx=max(distV[i], mx);
  cout << mx-1 << endl;
}