#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline bool uax(T &x, T y) {
  return (y > x) ? x = y, true : false;
}
template <typename T>
inline bool uin(T &x, T y) {
  return (y < x) ? x = y, true : false;
}
string to_string(char c) { return "'" + string(1, c) + "'"; }
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char *s) { return to_string((string)s); }
template <typename A>
string to_string(A);
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ": " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool f = false;
  string r = "{";
  for (auto x : v) {
    if (f) r += ", ";
    r += to_string(x);
    f = true;
  }
  return r += "}";
}
template <typename A>
string to_string(vector<vector<A>> v) {
  string r;
  for (auto x : v) r += "\n" + to_string(x);
  return r;
}
void err(istream_iterator<string>) { cerr << endl; }
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " =: " << to_string(a) << "; ";
  err(++it, args...);
}
template <typename T>
void kek(T ans) {
  cout << ans << endl;
  exit(0);
}
int const MOD = 1e9 + 7;
long long const INF = 1e18 + 42;
template <class Monoid>
class LCA {
  using T = typename Monoid::type;
  struct Edge {
    int to;
    T cost;
  };
  bool is_build;
  const int size;
  int log_size, root;
  vector<vector<int>> parent;
  vector<vector<T>> dp;
  vector<int> depth;
  vector<vector<Edge>> G;
  void dfs(int v, int pv) {
    parent[0][v] = pv;
    for (const auto &e : G[v]) {
      if (e.to != pv) {
        depth[e.to] = depth[v] + 1;
        dfs(e.to, v);
        dp[0][e.to] = e.cost;
      }
    }
  }

 public:
  LCA(const int n, const int _root)
      : is_build(false),
        size(n),
        log_size(0),
        root(_root),
        depth(size, 0),
        G(n) {
    for (int v = size; v > 0; v /= 2) ++log_size;
  }
  void add(int a, int b, T c) {
    G[a].push_back({b, c});
    G[b].push_back({a, c});
  }
  void build() {
    is_build = true;
    parent.assign(log_size, vector<int>(size, -1));
    dp.assign(log_size, vector<T>(size, Monoid::id()));
    dfs(root, -1);
    for (int k = 0; k < log_size - 1; ++k)
      for (int v = 0; v < size; ++v) {
        if (parent[k][v] < 0) {
          parent[k + 1][v] = -1;
          dp[k + 1][v] = dp[k][v];
        } else {
          parent[k + 1][v] = parent[k][parent[k][v]];
          dp[k + 1][v] = Monoid::op(dp[k][v], dp[k][parent[k][v]]);
        }
      }
  }
  T dist(int u, int v) {
    if (!is_build) build();
    if (depth[u] > depth[v]) std::swap(u, v);
    T res = Monoid::id();
    for (int k = 0; k < log_size; ++k) {
      if (((depth[v] - depth[u]) >> k) & 1) {
        res = Monoid::op(res, dp[k][v]);
        v = parent[k][v];
      }
    }
    if (u == v) return res;
    for (int k = log_size - 1; ~k; --k) {
      if (parent[k][u] != parent[k][v]) {
        res = Monoid::op(res, dp[k][u]);
        res = Monoid::op(res, dp[k][v]);
        u = parent[k][u];
        v = parent[k][v];
      }
    }
    res = Monoid::op(res, dp[0][u]);
    res = Monoid::op(res, dp[0][v]);
    return res;
  }
};
struct Sum {
  using type = int;
  static type id() { return 0; }
  static type op(const type &l, const type &r) { return l + r; }
};
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, x, y;
  cin >> n >> x >> y;
  --x, --y;
  LCA<Sum> g(n, 0);
  vector<int> deg(n);
  for (int i = 0; i < n - 1; ++i) {
    int u, v;
    cin >> u >> v, --u, --v;
    g.add(u, v, 1);
    g.add(v, u, 1);
    deg[u]++, deg[v]++;
  }
  g.build();
  int ans = 1;
  for (int i = 0; i < n; ++i)
    if (deg[i] == 1) {
      int tak = g.dist(x, i);
      int aok = g.dist(y, i);
      if (tak < aok) {
        aok -= tak;
        int cur = 2 * tak;
        if (aok & 1) {
          cur += (aok - 1) * 2;
          ++cur;
        } else {
          cur += (aok - 2) * 2;
          cur += 2;
        }
        uax(ans, cur / 2);
      }
    }
  kek(ans);
}
