#include <bits/stdc++.h>
using namespace std;
vector<long long int> adj_list[100002];
long long int found;
long long int u, v;
long long int to_u, to_v;
long long int farthest;
long long int caution;
long long int find_dist_to_v(long long int cur, long long int parent) {
  long long int distance_to_v = 0;
  long long int pos = -1;
  if (cur == v) {
    return 0;
  }
  for (auto x : adj_list[cur]) {
    if (x != parent) {
      long long int tmp = find_dist_to_v(x, cur);
      if (found == 1) {
        distance_to_v = tmp;
        pos = x;
        to_v = pos;
        break;
      }
    }
  }
  return distance_to_v + 1;
}
long long int find_dist_to_u(long long int cur, long long int parent) {
  long long int distance_to_v = 0;
  if (cur == u) {
    found = 1;
    return 0;
  }
  for (auto x : adj_list[cur]) {
    if (x != parent) {
      long long int tmp = find_dist_to_u(x, cur);
      if (found == 1) {
        distance_to_v = tmp;
        to_u = x;
        break;
      }
    }
  }
  return distance_to_v + 1;
}
long long int find_max_depth(long long int cur, long long int parent) {
  long long int max = -1;
  long long int pos = -1;
  if (cur == v) {
    caution = 1;
  }
  if (adj_list[cur].size() == 1) {
    pos = adj_list[cur][0];
  }
  for (auto x : adj_list[cur]) {
    if (x != parent && caution != 1) {
      long long int tmp = find_max_depth(x, cur);
      if (caution != 1 && max < tmp) {
        max = tmp;
        pos = x;
      }
      caution = 0;
    }
  }
  farthest = pos;
  return max + 1;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int T = 1, n, m;
  string str;
  while (T--) {
    long long int p = 0, q = 0, tmp = 0, sum = 0, count = 0;
    int flag = 0;
    cin >> n >> u >> v;
    for (long long int i = 1; i < n; i++) {
      cin >> p >> q;
      adj_list[p].emplace_back(q);
      adj_list[q].emplace_back(p);
    }
    while (u != v) {
      found = 0;
      to_u = -1, to_v = -1;
      farthest = -1;
      caution = 0;
      if (find_dist_to_v(u, 0) > 2) {
        u = to_v;
      } else {
        for (int i = 1; i <= n; ++i) {
        }
        find_max_depth(u, 0);
        u = farthest;
      }
      if (u == v) {
        break;
      }
      found = 0;
      to_u = -1, to_v = -1;
      farthest = -1;
      find_dist_to_u(v, 0);
      v = to_u;
      count++;
    }
    cout << count << "\n";
  }
  return 0;
}
