版本比较
LZM_Boruvka
正文
增加 135 行删除 0 行
228 行未改动全部展开229230231232228 行未改动全部展开所以这题相当于有 n 个任意两点间权值确定为 w,每次询问 (i, k),求 s 能否用边权不超过 k 的边来联通。所以转换为了 AT_cutezrr9178_e。228 行未改动全部展开229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367228 行未改动全部展开所以这题相当于有 n 个任意两点间权值确定为 w,每次询问 (i, k),求 s 能否用边权不超过 k 的边来联通。所以转换为了 AT_cutezrr9178_e。:::success[code]```cpp#include <bits/stdc++.h>#define int long longusing namespace std;const int N = 1e6 + 5;struct Edge {int x, y, w;};struct Node {int x, w;};int n, m, s, d;int f[N], a[N], dis[N], id[N];Edge p[N];vector<Node> v[N];int find(int x) {return f[x] == x ? x : f[x] = find(f[x]);}void merge(int x, int y) {int fx = find(x), fy = find(y);if (fx == fy) {return;}f[fy] = fx;}void add(int x, int y, int w) {v[x].emplace_back(Node{y, w});v[y].emplace_back(Node{x, w});}void dfs(int x, int fa) {for (auto i : v[x]) {if (i.x == fa) {continue;}dis[i.x] = max(dis[x], i.w);dfs(i.x, x);}}int CD(int x, int y) {return abs(abs(a[x] - a[y]) - d);}signed main() {cin.tie(0)->sync_with_stdio(0);cin >> n >> m >> s >> d;for (int i = 1; i <= n; i++) {cin >> a[i];f[i] = i;}while (1) {int top = 0;fiint(id + 1, id + 1 + n, -1);for (int i = 1; i <= n; i++) {int l = lower_bound(a + 1, a + 1 + n, a[i] - d) - a;int r = upper_bound(a + 1, a + 1 + n, a[i] + d) - a - 1;int w;if (l <= n && find(l) != find(i)) {w = CD(i, l);p[++top] = {i, l, w};if (id[find(i)] == -1 || p[top].w < p[id[find(i)]].w) {id[find(i)] = top;}if (id[find(l)] == -1 || p[top].w < p[id[find(l)]].w) {id[find(l)] = top;}}l--;if (l && find(l) != find(i)) {w = CD(i, l);p[++top] = {i, l, w};if (id[find(i)] == -1 || p[top].w < p[id[find(i)]].w) {id[find(i)] = top;}if (id[find(l)] == -1 || p[top].w < p[id[find(l)]].w) {id[find(l)] = top;}}if (r && find(r) != find(i)) {w = CD(i, r);p[++top] = {i, r, w};if (id[find(i)] == -1 || p[top].w < p[id[find(i)]].w) {id[find(i)] = top;}if (id[find(r)] == -1 || p[top].w < p[id[find(r)]].w) {id[find(r)] = top;}}r++;if (r <= n && find(r) != find(i)) {w = CD(i, r);p[++top] = {i, r, w};if (id[find(i)] == -1 || p[top].w < p[id[find(i)]].w) {id[find(i)] = top;}if (id[find(r)] == -1 || p[top].w < p[id[find(r)]].w) {id[find(r)] = top;}}}int fl = 0;for (int i = 1; i <= n; i++) {if (find(i) != i || id[i] < 0) {continue;}int x = p[id[i]].x, y = p[id[i]].y, w = p[id[i]].w;int fx = find(x), fy = find(y);if (fx != fy) {merge(x, y);fl = 1;add(x, y, w);}}if (!fl) {break;}}dfs(s, 0);for (int x, y; m--; ) {cin >> x >> y;cout << (dis[x] <= y ? "Yes" : "No") << '\n';}return 0;}```:::