#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const double EPS = 1e-7;
const int INF = 1 << 30;
const long long int LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
int n, u, v;
vector<vector<int>> g;
int bfs(int s) {
  vector<int> d(n, -1);
  d[s] = 0;
  queue<int> que;
  que.push(s);
  while (que.size()) {
    int now = que.front();
    que.pop();
    if (d[now] == -1) {
      continue;
    }
    for (auto next : g[now]) {
      if (d[next] == -1) {
        d[next] = d[now] + 1;
        que.push(next);
      }
    }
  }
  int res = *max_element((d).begin(), (d).end());
  for (int i = 0; i < n; i++) {
    if (d[i] == res) {
      return i;
    }
  }
}
int bfs2(int s, int goal) {
  vector<int> d(n, -1);
  d[s] = 0;
  queue<int> que;
  que.push(s);
  while (que.size()) {
    int now = que.front();
    que.pop();
    if (d[now] == -1) {
      continue;
    }
    for (auto next : g[now]) {
      if (d[next] == -1) {
        d[next] = d[now] + 1;
        que.push(next);
      }
    }
  }
  return d[goal];
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> u >> v;
  u--;
  v--;
  g.resize(n);
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].emplace_back(b);
    g[b].emplace_back(a);
  }
  auto f = bfs(u);
  auto g = bfs(f);
  cout << bfs2(f, g) - 1 << "\n";
}
