#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, u, v;
  cin >> N >> u >> v;
  u--;
  v--;
  vector<int> E[N];
  for (int i = 0; i < N - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    E[a].push_back(b);
    E[b].push_back(a);
  }
  int next_node_tow_u[N];
  for (int i = 0; i < N; i++) next_node_tow_u[i] = -1;
  queue<int> q;
  q.push(u);
  bool visited[N];
  for (int i = 0; i < N; i++) visited[N] = false;
  visited[u] = true;
  bool break_loop = false;
  while (!q.empty() && !break_loop) {
    int node = q.front();
    q.pop();
    int edge_count = E[node].size();
    for (int i = 0; (i < edge_count) && !break_loop; i++) {
      int next_node = E[node][i];
      if (!visited[next_node]) {
        visited[next_node] = true;
        next_node_tow_u[next_node] = node;
        if (next_node == v) {
          break_loop = true;
        }
        q.push(next_node);
      }
    }
  }
  list<int> path;
  int node = v;
  while (node != u) {
    path.push_back(node);
    node = next_node_tow_u[node];
  }
  path.push_back(u);
  int move_count = 0, far_from_u = -1;
  stack<int> path_to_far;
  list<int>::iterator path_it;
  for (int ii = 0; ii < 10; ii++) {
    path_it = path.end();
    path_it--;
    path_it--;
    if (path.size() <= 3 && far_from_u == -1) {
      queue<int> q2;
      q2.push(u);
      for (int i = 0; i < N; i++) visited[i] = false;
      visited[u] = true;
      while (!q2.empty()) {
        node = q2.front();
        q2.pop();
        int edge_count = E[node].size();
        for (int i = 0; i < edge_count; i++) {
          int next_node = E[node][i];
          if (!visited[next_node]) {
            visited[next_node] = true;
            next_node_tow_u[next_node] = node;
            if (next_node != *path_it) {
              q2.push(next_node);
            }
          }
        }
      }
      far_from_u = node;
      while (node != u) {
        path_to_far.push(node);
        node = next_node_tow_u[node];
      }
    }
    bool farther = false;
    if (far_from_u != -1) {
      if (u == far_from_u) {
        u = E[u][0];
        path_to_far.push(u);
      } else {
        u = path_to_far.top();
        path_to_far.pop();
        farther = true;
      }
    } else {
      u = *path_it;
    }
    if (u == v) break;
    if (farther)
      path.push_back(u);
    else
      path.pop_back();
    path_it = path.begin();
    path_it++;
    v = *path_it;
    move_count++;
    if (u == v) break;
    path.pop_front();
  }
  cout << move_count << endl;
}
