#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
struct BFSS {
  int depth, parent;
};
struct BFSS2 {
  int depth;
  bool is_child_of_x;
};
int bfs(const vvi &tree, vector<BFSS> &dist, int N, int start) {
  dist.resize(N);
  for (size_t i = 0; i < dist.size(); i++) {
    dist[i].depth = -1;
  }
  queue<int> next;
  dist[start].depth = 0;
  dist[start].parent = -1;
  next.push(start);
  int longest;
  while (!next.empty()) {
    int cp = next.front();
    next.pop();
    for (int node : tree[cp]) {
      if (dist[node].depth < 0) {
        dist[node].depth = dist[cp].depth + 1;
        dist[node].parent = cp;
        next.push(node);
        longest = node;
      }
    }
  }
  return longest;
}
int bfs_depth_x(const vvi &tree, vector<BFSS2> &dist, int N, int root, int x) {
  dist.resize(N);
  for (size_t i = 0; i < dist.size(); i++) {
    dist[i].depth = -1;
  }
  queue<int> next;
  dist[root].depth = 0;
  dist[root].is_child_of_x = false;
  next.push(root);
  int longest;
  while (!next.empty()) {
    int cp = next.front();
    next.pop();
    for (int node : tree[cp]) {
      if (dist[node].depth < 0) {
        dist[node].depth = dist[cp].depth + 1;
        if (node == x)
          dist[node].is_child_of_x = true;
        else
          dist[node].is_child_of_x = dist[cp].is_child_of_x;
        next.push(node);
        if (dist[node].is_child_of_x) {
          longest = node;
        }
      }
    }
  }
  return longest;
}
int lca(const vector<BFSS> &dist, int N, int root, int u, int v) {
  unordered_set<int> ancs;
  for (int n = u; n != root; n = dist[n].parent) {
    ancs.insert(n);
  }
  for (int n = v; n != root; n = dist[n].parent) {
    if (ancs.count(n)) {
      return n;
    }
  }
  return -1;
}
int main() {
  int N, u, v;
  cin >> N >> u >> v;
  vvi tree(N);
  for (int i = 0; i < N - 1; i++) {
    int a, b;
    cin >> a >> b;
    tree[a - 1].push_back(b - 1);
    tree[b - 1].push_back(a - 1);
  }
  --u;
  --v;
  vector<BFSS> distance;
  int longest_virt = bfs(tree, distance, N, v);
  bfs(tree, distance, N, longest_virt);
  int du = distance[u].depth, dv = distance[v].depth;
  if (dv <= du) {
    int uv_lca = lca(distance, N, longest_virt, u, v);
    vector<BFSS2> dist_from_lca;
    int longest_virt_to_u = bfs_depth_x(tree, dist_from_lca, N, uv_lca, u);
    int lu = dist_from_lca[longest_virt_to_u].depth;
    du = lu - dist_from_lca[u].depth;
    dv = lu + dist_from_lca[v].depth;
  }
  int ans = du + (dv - du) / 2;
  cout << ans << endl;
  return 0;
}
