#include <bits/stdc++.h>
using namespace std;
class lca {
 public:
  int n, logn;
  vector<vector<int>> parent;
  vector<int> depth;
  lca(vector<vector<int>> &tree, int rt = 0) {
    n = (int)tree.size(), logn = log2(n) + 1;
    parent.resize(n, vector<int>(logn));
    depth.resize(n);
    function<void(int, int, int)> dfs = [&](int u, int p, int d) {
      parent[u][0] = p;
      depth[u] = d;
      for (int v : tree[u]) {
        if (v == p) continue;
        dfs(v, u, d + 1);
      }
    };
    dfs(rt, -1, 0);
    for (int k = 0; k + 1 < logn; k++) {
      for (int u = 0; u < n; u++) {
        if (parent[u][k] < 0) {
          parent[u][k + 1] = -1;
        } else {
          parent[u][k + 1] = parent[parent[u][k]][k];
        }
      }
    }
  }
  int get(int u, int v) {
    if (depth[u] > depth[v]) swap(u, v);
    for (int k = 0; k < logn; k++) {
      if ((depth[v] - depth[u]) >> k & 1) {
        v = parent[v][k];
      }
    }
    if (u == v) return u;
    for (int k = logn - 1; k >= 0; k--) {
      if (parent[u][k] != parent[v][k]) {
        u = parent[u][k];
        v = parent[v][k];
      }
    }
    return parent[u][0];
  }
  int log2(int b) { return 31 - __builtin_clz(b); }
};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, s, t;
  cin >> n >> s >> t;
  s--;
  t--;
  vector<vector<int>> tree(n);
  for (int i = 1; i < n; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    tree[a].push_back(b);
    tree[b].push_back(a);
  }
  vector<int> depth(n);
  int max_depth = 0, rt = -1;
  function<void(int, int, int)> dfs = [&](int u, int d, int p = -1) {
    depth[u] = d;
    for (int v : tree[u]) {
      if (v == p) continue;
      dfs(v, d + 1, u);
      if (v == t) continue;
      if (depth[v] > max_depth) {
        max_depth = depth[v];
        rt = v;
      }
    }
  };
  dfs(s, 0, -1);
  if (rt == -1) {
    cout << "0\n";
    return 0;
  }
  lca lc(tree, rt);
  int p = lc.get(s, t);
  if (lc.depth[s] > lc.depth[t]) {
    cout << lc.depth[s] + lc.depth[t] - 2 * lc.depth[p] - 1 << '\n';
  } else {
    cout << lc.depth[t] - 1 << '\n';
  }
  return 0;
}
