#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

struct tree {
  int n, logn;
  vector<vector<int>> adj;
  tree(int n)
      : n(n), adj(n) {
    logn = 1;
    for (int k = 1; k < n; k *= 2) ++logn;
  }
  void add_edge(int s, int t) {
    adj[s].push_back(t);
    adj[t].push_back(s);
  }
  vector<vector<int>> parent;
  vector<int> rank, depth;
  void rootify(int r) {
    parent.assign(logn, vector<int>(n, r));
    rank.resize(n);
    depth.assign(n, 0);
    int id = 0;
    function<void(int, int)> dfs = [&](int u, int p) {
      rank[u] = id++;
      parent[0][u] = p;
      for (int i = 0; i + 1 < logn; ++i)
        parent[i + 1][u] = parent[i][parent[i][u]];
      for (int v : adj[u])
        if (v != p) {
          depth[v] = depth[u] + 1;
          dfs(v, u);
        }
    };
    dfs(r, r);
  }

  int lca(int u, int v) {
    if (depth[u] > depth[v]) swap(u, v);
    for (int i = depth[v] - depth[u], k = 0; i; i /= 2) {
      if (i & 1) v = parent[k][v];
      ++k;
    }
    if (u == v) return u;
    for (int i = logn - 1; i >= 0; --i) {
      if (parent[i][u] != parent[i][v]) {
        u = parent[i][u];
        v = parent[i][v];
      }
    }
    return parent[0][u];
  }

  int dist(int u, int v) {
    int r = lca(u, v);
    return depth[u] + depth[v] - 2 * depth[r];
  }
};

int main() {
#ifdef DEBUG
  ifstream ifs("in.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
  int N, a, b;
  while (cin >> N >> a >> b) {
    --a;
    --b;
    vec<int, 2> G(N);
    tree lca(N);
    for (int i = 0; i < N - 1; i++) {
      int u, v;
      cin >> u >> v;
      --u;
      --v;
      G[u].push_back(v);
      G[v].push_back(u);
      lca.add_edge(v, u);
    }
    if (N == 2) {
      cout << 0 << endl;
      continue;
    }
    int r = -1;
    for (int v = 0; v < N; v++) {
      if (G[v].size() > 1) r = v;
    }
    assert(r >= 0);
    vector<int> is_leaf(N, 0);
    auto dfs = [&](auto& dfs, int v, int p = -1) -> void {
      bool leaf = true;
      for (int u : G[v]) {
        if (u == p) continue;
        dfs(dfs, u, v);
        leaf = false;
      }
      is_leaf[v] = leaf;
    };
    dfs(dfs, r, -1);
    lca.rootify(r);
    int res = 0;
    // 高橋終了
    for (int x = 0; x < N; x++) {
      if (is_leaf[x]) continue;
      int da = lca.dist(a, x);
      int db = lca.dist(b, x);
      if (da % 2 == db % 2) continue;
      if (da > db + 1) continue;
      chmax(res, db);
    }
    // 青木終了
    for (int x = 0; x < N; x++) {
      if (is_leaf[x]) continue;
      int da = lca.dist(a, x);
      int db = lca.dist(b, x);
      if (da % 2 != db % 2) continue;
      if (da > db) continue;
      chmax(res, db);
    }
    cout << res << endl;
  }
  return 0;
}
