#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
const int MAX{200010};
const ll MOD{1000000007}, oo{1LL << 62};
vector<int> adj[MAX];
struct LCA {
  vector<int> height, euler, first, segtree;
  vector<bool> visited;
  int n;
  LCA(int N, int root = 0) {
    n = N;
    height.resize(n);
    first.resize(n);
    euler.reserve(n * 2);
    visited.assign(n, false);
    dfs(root);
    int m = euler.size();
    segtree.resize(m * 4);
    build(1, 0, m - 1);
  }
  void dfs(int node, int 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(to, h + 1);
        euler.push_back(node);
      }
    }
  }
  void build(int node, int b, int e) {
    if (b == e) {
      segtree[node] = euler[b];
    } else {
      int mid = (b + e) / 2;
      build(node << 1, b, mid);
      build(node << 1 | 1, mid + 1, e);
      int l = segtree[node << 1], r = segtree[node << 1 | 1];
      segtree[node] = (height[l] < height[r]) ? l : r;
    }
  }
  int query(int node, int b, int e, int L, int R) {
    if (b > R || e < L) return -1;
    if (b >= L && e <= R) return segtree[node];
    int mid = (b + e) >> 1;
    int left = query(node << 1, b, mid, L, R);
    int 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;
  }
  int lca(int u, int v) {
    int left = first[u], right = first[v];
    if (left > right) swap(left, right);
    return query(1, 0, euler.size() - 1, left, right);
  }
};
int ps[MAX], is_leaf[MAX];
void dfs(int u, int p) {
  ps[u] = p;
  bool leaf = true;
  for (auto v : adj[u]) {
    if (v != p) {
      leaf = false;
      dfs(v, u);
    }
  }
  is_leaf[u] = leaf;
}
vector<int> path(int u, int v) {
  dfs(u, 0);
  vector<int> vs(1, v);
  int p = ps[v];
  while (p) {
    vs.push_back(p);
    p = ps[p];
  }
  reverse(vs.begin(), vs.end());
  return vs;
}
ll solve(int N, int a, int b) {
  LCA xs(N + 1, a);
  dfs(a, 0);
  int v = 0, d = 0, g = 0;
  for (int u = 1; u <= N; ++u) {
    if (u == a or u == b) continue;
    auto p = xs.lca(u, b);
    if (is_leaf[u] and xs.height[p] < (xs.height[b] - xs.height[p]) and
        xs.height[u] > d) {
      v = u;
      d = xs.height[u];
      g = p;
    }
  }
  if (v == 0) {
    v = adj[a].front();
  }
  vector<int> p = path(a, v), q = path(b, g ? g : a);
  int ans = 0, x = 0, y = 0;
  N = p.size();
  int M = q.size();
  while (y < M - 1) {
    if (x < N - 1)
      ++x;
    else
      x = N - 2;
    if (p[x] == q[y]) return ans;
    ++ans;
    ++y;
    if (q[y] == p[x]) return ans;
  }
  q = path(q.back(), v);
  M = q.size();
  y = 0;
  while (y < M - 1) {
    if (x < N - 1)
      ++x;
    else
      x = N - 2;
    if (p[x] == q[y]) return ans;
    ++ans;
    ++y;
    if (q[y] == p[x]) return ans;
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(false);
  int N, u, v;
  cin >> N >> u >> v;
  vector<ll> xs(N);
  for (int i = 0; i < N - 1; ++i) {
    int a, b;
    cin >> a >> b;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  auto ans = solve(N, u, v);
  cout << ans << '\n';
  return 0;
}
