#include <bits/stdc++.h>
using namespace std;
using P = pair<long long int, long long int>;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
struct Edge {
  int to;
  long long int weight;
  Edge(int t, long long int w) : to(t), weight(w) {}
};
int N;
int u, v;
using Graph = vector<vector<int>>;
long long int dist_u[110000];
long long int dist_v[110000];
int main() {
  cin >> N >> u >> v;
  Graph G(N + 1);
  for (int i = 0; i < N - 1; ++i) {
    int a, b;
    cin >> a >> b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  queue<int> que;
  que.push(v);
  int cur = 0;
  for (int i = 1; i <= N; ++i) {
    dist_v[i] = -1;
  }
  while (!que.empty()) {
    queue<int> new_q;
    int n = que.size();
    for (int i = 0; i < n; ++i) {
      int tmp = que.front();
      que.pop();
      if (dist_v[tmp] == -1) {
        dist_v[tmp] = cur;
        for (auto nv : G[tmp]) {
          new_q.push(nv);
        }
      }
    }
    que = new_q;
    cur++;
  }
  que.push(u);
  cur = 0;
  for (int i = 1; i <= N; ++i) {
    dist_u[i] = -1;
  }
  while (!que.empty()) {
    queue<int> new_q;
    int n = que.size();
    for (int i = 0; i < n; ++i) {
      int tmp = que.front();
      que.pop();
      if (dist_u[tmp] == -1) {
        dist_u[tmp] = cur;
        for (auto nv : G[tmp]) {
          new_q.push(nv);
        }
      }
    }
    que = new_q;
    cur++;
  }
  vector<long long int> dist(110000);
  long long int ans = 0;
  for (int i = 1; i <= N; ++i) {
    dist[i] = dist_v[i] - dist_u[i];
    if (dist[i] <= 0) {
      continue;
    } else {
      bool flg = false;
      for (auto nv : G[i]) {
        if (dist[nv] > 0) flg = true;
      }
      ans = max(ans, dist_u[i] + dist[i] / 2);
    }
  }
  cout << ans << "\n";
}
