#include <bits/stdc++.h>
using namespace std;
vector<long long int> dx = {-1, 1, 0, 0, -1, -1, 1, 1};
vector<long long int> dy = {0, 0, 1, -1, -1, 1, -1, 1};
long long int gcd(long long int a, long long int b) {
  return b ? gcd(b, a % b) : a;
}
long long int lcm(long long int a, long long int b) {
  return a / gcd(a, b) * b;
}
template <typename T>
struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template <typename T>
using Edges = vector<edge<T> >;
template <typename T>
using WeightedGraph = vector<Edges<T> >;
using UnWeightedGraph = vector<vector<int> >;
template <typename T>
using Matrix = vector<vector<T> >;
template <typename T>
void dijkstra(WeightedGraph<T> &g, vector<T> &dist, vector<T> &prev,
              vector<T> &num, int s) {
  T N = g.size();
  dist.resize(N, (long long int)1e18);
  prev.resize(N, -1);
  num.resize(N, 0);
  using Pi = pair<T, int>;
  priority_queue<Pi, vector<Pi>, greater<Pi> > que;
  dist[s] = 0;
  que.emplace(dist[s], s);
  while (!que.empty()) {
    T cost;
    int idx;
    tie(cost, idx) = que.top();
    que.pop();
    if (dist[idx] < cost) continue;
    for (auto &e : g[idx]) {
      auto next_cost = cost + e.cost;
      if (dist[e.to] < next_cost) continue;
      if (dist[e.to] == next_cost) {
        num[e.to] += num[idx];
        num[e.to] %= 1000000007;
        continue;
      }
      dist[e.to] = next_cost;
      prev[e.to] = idx;
      num[e.to] = num[idx];
      que.emplace(dist[e.to], e.to);
    }
  }
  return;
}
template <typename T>
vector<T> get_path(const vector<T> &prev, T t) {
  vector<T> path;
  for (T cur = t; cur != -1; cur = prev[cur]) {
    path.push_back(cur);
  }
  reverse(path.begin(), path.end());
  return path;
}
int main() {
  long long int N, u, v;
  cin >> N >> u >> v;
  u--;
  v--;
  WeightedGraph<long long int> G(N);
  for (long long int i = 0LL; i < (long long int)(N - 1); i++) {
    long long int a, b;
    cin >> a >> b;
    a--;
    b--;
    G[a].emplace_back(b, 1);
    G[b].emplace_back(a, 1);
  }
  vector<long long int> dist1, prev1, num1;
  dijkstra(G, dist1, prev1, num1, u);
  vector<long long int> dist2, prev2, num2;
  dijkstra(G, dist2, prev2, num2, v);
  long long int ma = 0;
  long long int mi = (long long int)1e18;
  bool flag = false;
  for (long long int i = 0LL; i < (long long int)(N); i++) {
    if (dist1[i] < dist2[i]) ma = max(ma, min(dist1[i], dist2[i]));
    if (dist1[i] == dist2[i]) {
      flag = true;
      mi = min(mi, dist1[i]);
    }
  }
  if (flag) {
    cout << mi << endl;
  } else {
    cout << ma << endl;
  }
  return 0;
}
