#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
const long long mod = 1e9 + 7;
const long long mod1 = 998244353;
const long long big = 1e18;
const double PI = 2 * asin(1);
int main() {
  int N, u, v;
  cin >> N >> u >> v;
  u--;
  v--;
  vector<vector<int> > edge(N);
  int A, B;
  for (int i = 0; i < N - 1; ++i) {
    cin >> A >> B;
    A--;
    B--;
    edge[A].push_back(B);
    edge[B].push_back(A);
  }
  int tdist[N], adist[N];
  for (int i = 0; i < N; ++i) {
    tdist[i] = -1;
    adist[i] = -1;
  }
  queue<pair<int, int> > que;
  pair<int, int> state;
  int node, dist;
  que.push(make_pair(u, 0));
  while (!que.empty()) {
    state = que.front();
    que.pop();
    node = state.first;
    dist = state.second;
    if (tdist[node] > -1) continue;
    tdist[node] = dist;
    for (int i = 0; i < edge[node].size(); ++i) {
      if (tdist[edge[node][i]] > -1) continue;
      que.push(make_pair(edge[node][i], dist + 1));
    }
  }
  que.push(make_pair(v, 0));
  while (!que.empty()) {
    state = que.front();
    que.pop();
    node = state.first;
    dist = state.second;
    if (adist[node] > -1) continue;
    adist[node] = dist;
    for (int i = 0; i < edge[node].size(); ++i) {
      if (adist[edge[node][i]] > -1) continue;
      que.push(make_pair(edge[node][i], dist + 1));
    }
  }
  int ansnode = 0;
  for (int i = 0; i < N; ++i) {
    if (tdist[i] < adist[i] && adist[i] > adist[ansnode]) ansnode = i;
  }
  cout << adist[ansnode] - 1 << endl;
}
