#include <bits/stdc++.h>
using namespace std;
const long long M = 1e9 + 7;
vector<vector<long long>> g;
struct LCA {
  vector<long long> height, euler, first, segtree;
  vector<bool> visited;
  long long n;
  LCA(vector<vector<long long>> &adj, long long root = 0) {
    n = adj.size();
    height.resize(n);
    first.resize(n);
    euler.reserve(n * 2);
    visited.assign(n, false);
    dfs(adj, root);
    long long m = euler.size();
    segtree.resize(m * 4);
    build(1, 0, m - 1);
  }
  void dfs(vector<vector<long long>> &adj, long long node, long long h = 0) {
    visited[node] = true;
    height[node] = h;
    first[node] = euler.size();
    euler.push_back(node);
    for (auto to : adj[node]) {
      if (!visited[to]) {
        dfs(adj, to, h + 1);
        euler.push_back(node);
      }
    }
  }
  void build(long long node, long long b, long long e) {
    if (b == e) {
      segtree[node] = euler[b];
    } else {
      long long mid = (b + e) / 2;
      build(node << 1, b, mid);
      build(node << 1 | 1, mid + 1, e);
      long long l = segtree[node << 1], r = segtree[node << 1 | 1];
      segtree[node] = (height[l] < height[r]) ? l : r;
    }
  }
  long long query(long long node, long long b, long long e, long long L,
                  long long R) {
    if (b > R || e < L) return -1;
    if (b >= L && e <= R) return segtree[node];
    long long mid = (b + e) >> 1;
    long long left = query(node << 1, b, mid, L, R);
    long long right = query(node << 1 | 1, mid + 1, e, L, R);
    if (left == -1) return right;
    if (right == -1) return left;
    return height[left] < height[right] ? left : right;
  }
  long long lca(long long u, long long v) {
    long long left = first[u], right = first[v];
    if (left > right) swap(left, right);
    return query(1, 0, euler.size() - 1, left, right);
  }
  long long dist(long long u, long long v) {
    long long lc = lca(u, v);
    return height[u] + height[v] - 2 * height[lc];
  }
};
int32_t main() {
  long long n, a, b;
  cin >> n >> a >> b;
  --a;
  --b;
  if (a == b) {
    cout << "0\n";
    return 0;
  }
  g.resize(n);
  for (long long i = 0; i < n - 1; ++i) {
    long long u, v;
    cin >> u >> v;
    u--;
    v--;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  LCA t(g);
  long long ans = t.dist(a, b) / 2;
  for (long long i = 0; i < n; ++i) {
    long long mid = t.lca(i, b);
    if (mid == t.lca(i, a) && t.dist(mid, a) <= t.dist(mid, b)) {
      ans = max(ans, min(t.dist(mid, b), t.dist(a, mid)));
      continue;
    }
    ans = max(ans, min(t.dist(i, a), t.dist(i, b)));
  }
  cout << ans << endl;
  return 0;
}
