#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
inline bool chmax(A &a, B b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename A, typename B>
inline bool chmin(A &a, B b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll << 30;
constexpr ll longINF = 1ll << 60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
struct LowestCommonAncestor {
 public:
  LowestCommonAncestor(std::size_t _size) : _size(_size) {
    g.resize(_size);
    isbuilt = false;
  }
  LowestCommonAncestor(std::vector<std::vector<int> > g, bool isper = true)
      : g(g) {
    _size = g.size();
    if (isper) build();
  };
  void add_edge(int s, int t) { g[s].push_back(t); }
  void clear() {
    _size = 0;
    g.clear();
    par.clear();
    depth.clear();
    isbuilt = false;
  }
  void build(int rootNode = 0) {
    logsize = 1;
    while (1 << logsize < _size) ++logsize;
    depth.resize(_size, -1);
    par.resize(logsize, std::vector<int>(_size, -1));
    depth[rootNode] = 0;
    dfs(rootNode, -1);
    for (int i = 1; i < logsize; ++i) {
      for (int j = 0; j < _size; ++j) {
        if (~par[i - 1][j]) par[i][j] = par[i - 1][par[i - 1][j]];
      }
    }
    isbuilt = true;
  }
  int find(int a, int b) {
    assert(isbuilt);
    if (depth[a] < depth[b]) std::swap(a, b);
    int up = depth[a] - depth[b];
    for (int i = 0; i < logsize; ++i)
      if (up >> i & 1) a = par[i][a];
    if (a == b) return a;
    for (int i = logsize - 1; i >= 0; i--) {
      if (par[i][a] != par[i][b]) {
        a = par[i][a];
        b = par[i][b];
      }
    }
    return par[0][a];
  }
  int query(int a, int b) {
    assert(isbuilt);
    return depth[a] + depth[b] - 2 * depth[find(a, b)];
  }

 private:
  std::size_t _size, logsize;
  std::vector<std::vector<int> > g, par;
  std::vector<int> depth;
  bool isbuilt;
  void dfs(int u, int p) {
    for (int v : g[u]) {
      if (v == p) continue;
      depth[v] = depth[u] + 1;
      par[0][v] = u;
      dfs(v, u);
    }
  }
};
int N, U, V;
std::vector<std::vector<int> > g;
int func(int d) {
  int x = d / 2;
  int res = x * 2;
  d -= 2 * x;
  return res;
}
int func2(int d) {
  int res = 0;
  if (d <= 1) return 0;
  res++;
  d -= 2;
  res += func(d);
  return res;
}
int main() {
  cin >> N >> U >> V;
  U--;
  V--;
  g.resize(N);
  for (int i = (0); i < (N - 1); ++i) {
    int A, B;
    scanf("%d %d", &A, &B);
    A--;
    B--;
    g[A].push_back(B);
    g[B].push_back(A);
  }
  LowestCommonAncestor lca(g, false);
  lca.build(V);
  int D = lca.query(U, V);
  int ans = 0;
  for (int i = (0); i < (N); ++i) {
    int lc = lca.find(U, i);
    if (lc == V) continue;
    int curD = D;
    if (lc == U) {
      int d = lca.query(U, i);
      int cur = d + func2(D);
      chmax(ans, cur);
    } else if (lc == i) {
      int d = lca.query(U, i);
      curD -= d * 2;
      if (curD <= 0) {
        if (curD == 0)
          chmax(ans, d);
        else if (curD == -1)
          chmax(ans, d - 1);
        continue;
      }
      int cur = d + func(curD);
      chmax(ans, cur);
    } else {
      int d = lca.query(lc, U);
      curD -= d * 2;
      if (curD <= 0) {
        if (curD == 0)
          chmax(ans, d);
        else if (curD == -1)
          chmax(ans, d - 1);
        continue;
      }
      int d2 = lca.query(lc, i);
      int cur = d + d2 + func2(curD);
      chmax(ans, cur);
    }
  }
  cout << ans << endl;
  return 0;
}
