private int BinSearch(int a, int b, int need, int M, PersistentPartialUnionFind uf) { int L = -1, R = M; while (R - L > 1) { int mid = L + R >> 1; int x = uf.Root(a, mid); int y = uf.Root(b, mid); int num = uf.NumElements(x, mid); if (num < need && x != y) { num += uf.NumElements(y, mid); } if (num >= need) { R = mid; } else { L = mid; } } return(R); }
private int BinSearch(int a, int b, int need, int M, PersistentPartialUnionFind uf) { int L = -1, R = M; while (R - L > 1) { int mid = L + R >> 1; int num = uf.NumElements(a, mid) + (uf.Same(a, b, mid) ? 0 : uf.NumElements(b, mid)); if (num >= need) { R = mid; } else { L = mid; } } return(R); }