#include <bits/stdc++.h>
using ll = std::int64_t;
using P = std::tuple<int, int>;
template <typename M>
struct SegmentTree {
  using T = typename M::type;
  int numLeaves;
  std::vector<T> data;
  SegmentTree(int n) {
    numLeaves = 1;
    while (numLeaves < n) {
      numLeaves *= 2;
    }
    data.resize(numLeaves * 2);
    std::fill(data.begin() + numLeaves, data.end(), M::identity());
    for (int i = numLeaves - 1; i > 0; --i) {
      data[i] = M::bop(data[i * 2], data[i * 2 + 1]);
    }
  }
  template <typename F>
  SegmentTree(int n, F f) {
    numLeaves = 1;
    while (numLeaves < n) {
      numLeaves *= 2;
    }
    data.resize(numLeaves * 2);
    for (int i = 0; i < n; ++i) {
      data[i + numLeaves] = std::move(f(i));
    }
    std::fill(data.begin() + numLeaves + n, data.end(), M::identity());
    for (int i = numLeaves - 1; i > 0; --i) {
      data[i] = M::bop(data[i * 2], data[i * 2 + 1]);
    }
  }
  void set(int k, T v) {
    k += numLeaves;
    data[k] = v;
    while (k > 1) {
      k /= 2;
      data[k] = M::bop(data[k * 2], data[k * 2 + 1]);
    }
  }
  T product(int l, int r) {
    l += numLeaves;
    r += numLeaves;
    T pl = M::identity(), pr = M::identity();
    for (; l < r; l /= 2, r /= 2) {
      if (l & 1) {
        pl = M::bop(pl, data[l]);
        l += 1;
      }
      if (r & 1) {
        r -= 1;
        pr = M::bop(data[r], pr);
      }
    }
    return M::bop(pl, pr);
  }
  T at(int i) { return data[i + numLeaves]; }
};
struct M {
  using type = P;
  static type identity() {
    return std::make_tuple(std::numeric_limits<int>::max(), -1);
  }
  static type bop(type &m1, type &m2) { return std::min(m1, m2); }
};
int N, U, V;
std::vector<int> G[100100];
int depth[100100], in[100100];
SegmentTree<M> seg(200100);
void dfs(int v, int p, int d, int &i) {
  depth[v] = d;
  in[v] = i;
  seg.set(i, std::make_tuple(d, v));
  i += 1;
  for (int w : G[v]) {
    if (w == p) {
      continue;
    }
    dfs(w, v, d + 1, i);
    seg.set(i, std::make_tuple(d, v));
    i += 1;
  }
}
int lca(int v, int w) {
  if (in[v] > in[w]) {
    std::swap(v, w);
  }
  int x;
  std::tie(std::ignore, x) = seg.product(in[v], in[w]);
  return x;
}
int main() {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  std::cin >> N >> U >> V;
  for (int i = 0; i < N - 1; ++i) {
    int a, b;
    std::cin >> a >> b;
    G[a].emplace_back(b);
    G[b].emplace_back(a);
  }
  {
    int i = 0;
    dfs(V, -1, 0, i);
  }
  int res = 0;
  for (int i = 1; i <= N; ++i) {
    if (G[i].size() == 1) {
      continue;
    }
    int v = lca(i, U);
    int d_Uv = std::abs(depth[U] - depth[v]), d_Vv = depth[v];
    if (d_Uv < d_Vv || (i == v && d_Uv == d_Vv)) {
      res = std::max(res, depth[i]);
    }
  }
  std::cout << res << std::endl;
}
