#include <bits/stdc++.h>
using namespace std;
struct LCA {
  static const long long MAX_LOG_V = 21;
  vector<vector<long long>> G;
  vector<vector<long long>> parent;
  vector<long long> depth;
  LCA(long long size) {
    G = vector<vector<long long>>(size);
    parent = vector<vector<long long>>(MAX_LOG_V, vector<long long>(size));
    depth = vector<long long>(size);
  }
  void dfs(long long v, long long p, long long d) {
    parent[0][v] = p;
    depth[v] = d;
    for (long long i = 0; i < G[v].size(); i++) {
      if (G[v][i] != p) dfs(G[v][i], v, d + 1);
    }
  }
  void init(long long root, long long V) {
    dfs(root, -1, 0);
    for (long long k = 0; k + 1 < MAX_LOG_V; k++) {
      for (long long v = 0; v < V; v++) {
        if (parent[k][v] < 0)
          parent[k + 1][v] = -1;
        else
          parent[k + 1][v] = parent[k][parent[k][v]];
      }
    }
  }
  long long get(long long u, long long v) {
    if (depth[u] > depth[v]) swap(u, v);
    for (long long k = 0; k < MAX_LOG_V; k++) {
      if ((depth[v] - depth[u]) >> k & 1) {
        v = parent[k][v];
      }
    }
    if (u == v) return u;
    for (long long k = MAX_LOG_V - 1; k >= 0; k--) {
      if (parent[k][u] != parent[k][v]) {
        u = parent[k][u];
        v = parent[k][v];
      }
    }
    return parent[0][u];
  }
};
class f {
 public:
  static constexpr long long kStressIterations = 0;
  static void generateTest(std::ostream& test) {}
  set<long long> leaf;
  void dfs(vector<vector<long long>>& G, long long v, long long p) {
    bool ok = true;
    for (long long i = 0, i_len = (G[v].size()); i < i_len; ++i) {
      long long to = G[v][i];
      if (to == p) continue;
      dfs(G, to, v);
      ok = false;
    }
    if (ok) leaf.insert(v);
  }
  void solve(std::istream& cin, std::ostream& cout) {
    long long n, u, v;
    cin >> n >> u >> v;
    u--, v--;
    LCA lca(n);
    for (long long i = 0, i_len = (n - 1); i < i_len; ++i) {
      long long a, b;
      cin >> a >> b;
      a--, b--;
      lca.G[a].push_back(b);
      lca.G[b].push_back(a);
    }
    leaf.insert(0);
    lca.init(0, n);
    long long p = lca.get(u, v);
    long long dis = lca.depth[u] - lca.depth[p] + lca.depth[v] - lca.depth[p];
    if (dis == 1) {
      bool ok = true;
      for (auto k : lca.G[u]) {
        if (k == v) continue;
        ok = false;
      }
      if (ok) {
        cout << 0 << endl;
        return;
      }
    }
    dfs(lca.G, 0, -1);
    long long res = -1;
    for (auto l : leaf) {
      long long p1 = lca.get(l, u);
      long long p2 = lca.get(p1, v);
      long long dis1 = lca.depth[u] - lca.depth[p1];
      long long dis2 =
          lca.depth[p1] - lca.depth[p2] + lca.depth[v] - lca.depth[p2];
      if (dis2 <= dis1) continue;
      long long tmp = dis2 + lca.depth[l] - lca.depth[p1];
      res = max(res, tmp - 1);
    }
    cout << res << endl;
  }
};
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  f solver;
  solver.solve(in, out);
  return 0;
}
