#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1000000007;
const long long int INF = (long long int)1e15;
struct Vertex {
  vector<long long int> node;
};
Vertex V[100005];
long long int T[100005];
long long int A[100005];
int main() {
  long long int N, u, v;
  cin >> N >> u >> v;
  u--;
  v--;
  for (long long int(i) = (0); (i) < (N - 1); ++(i)) {
    long long int a, b;
    cin >> a >> b;
    a--;
    b--;
    V[a].node.push_back(b);
    V[b].node.push_back(a);
  }
  {
    memset(A, -1, sizeof(A));
    A[v] = 0;
    queue<pair<long long int, long long int> > q;
    q.push(pair<long long int, long long int>(v, 0));
    while (!q.empty()) {
      pair<long long int, long long int> t = q.front();
      q.pop();
      for (long long int(i) = (0); (i) < (V[t.first].node.size()); ++(i)) {
        long long int n = V[t.first].node[i];
        if (A[n] >= 0) continue;
        A[n] = t.second + 1;
        q.push(pair<long long int, long long int>(n, t.second + 1));
      }
    }
  }
  long long int max = 0;
  {
    memset(T, -1, sizeof(T));
    T[u] = 0;
    queue<pair<long long int, long long int> > q;
    q.push(pair<long long int, long long int>(u, 0));
    while (!q.empty()) {
      pair<long long int, long long int> t = q.front();
      q.pop();
      long long int k = t.first;
      max = std::max(max, T[k]);
      if (V[k].node.size() >= 2) {
        long long int m = (A[k] - T[k]) / 2;
        max = std::max(max, T[k] + m * 2);
      }
      for (long long int(i) = (0); (i) < (V[t.first].node.size()); ++(i)) {
        long long int n = V[t.first].node[i];
        if (T[n] >= 0) continue;
        T[n] = t.second + 1;
        if (T[n] > A[n]) continue;
        max = std::max(max, T[n]);
        if (V[n].node.size() >= 2) {
          long long int m = (A[n] - T[n]) / 2;
          max = std::max(max, T[n] + m * 2);
        }
        if (T[n] < A[n])
          q.push(pair<long long int, long long int>(n, t.second + 1));
      }
    }
  }
  cout << max << endl;
  return 0;
}
