QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#290677 | #6144. 支配 | MoRanSky | 100 ✓ | 332ms | 13204kb | C++23 | 2.1kb | 2023-12-25 06:24:54 | 2023-12-25 06:24:54 |
Judging History
answer
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#define pb push_back
using namespace std;
const int N = 3e3 + 5, M = 2 * N;
int n, m, Q, s, q[N], dep[N], fa[N], sz[N], dfn[N], dfncnt, ban, c[N];
bool st[N][N], vis[N];
int head[N], numE = 0;
struct E{
int next, v;
} e[M];
void inline add(int u, int v) {
e[++numE] = (E) { head[u], v };
head[u] = numE;
}
void dfs(int u) {
st[s][u] = false;
for (int i = head[u]; i; i = e[i].next) {
int v = e[i].v;
if (v != s && st[s][v]) dfs(v);
}
}
vector<int> g[N], g2[N];
int cnt[N];
void inline build() {
int hh = 0, tt = 0;
q[0] = 1;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
if (st[i][j]) cnt[j]++;
while (hh <= tt) {
int u = q[hh++];
for (int v = 1; v <= n; v++) {
if (!st[u][v]) continue;
st[u][v] = false, cnt[v]--;
if (cnt[v] == 1) g[u].pb(v), q[++tt] = v;
}
}
}
void dfs2(int u) {
dfn[u] = ++dfncnt;
sz[u] = 1;
for (int i = 0; i < g[u].size(); i++) {
int v = g[u][i];
if (v == fa[u]) continue;
fa[v] = u, dep[v] = dep[u] + 1;
dfs2(v);
sz[u] += sz[v];
}
}
int inline lca(int x, int y) {
while (x != y) {
if (dep[x] < dep[y]) swap(x, y);
x = fa[x];
}
return x;
}
void dfs3(int u) {
st[s][u] = 1;
for (int i = 0; i < g2[u].size(); i++) {
int v = g2[u][i];
if (v == ban) continue;
if (!st[s][v]) dfs3(v);
}
}
int main() {
scanf("%d%d%d", &n, &m, &Q);
for (int i = 1, u, v; i <= m; i++) {
scanf("%d%d", &u, &v);
add(u, v); g2[v].pb(u);
}
memset(st, 1, sizeof st);
for (s = 2; s <= n; s++) dfs(1);
build();
dfs2(1);
for (s = 2; s <= n; s++) {
ban = fa[s];
dfs3(s);
}
while (Q--) {
int x, y; scanf("%d%d", &x, &y);
int p = x;
while (p) {
vis[p] = 1;
p = fa[p];
}
for (int i = 2; i <= n; i++) {
if (vis[fa[i]] || y == fa[i]) continue;
if (st[i][y]) {
c[dfn[i]]++, c[dfn[i] + sz[i]]--;
}
}
int ans = 0;
for (int i = 1; i <= n; i++) {
c[i] += c[i - 1];
if (c[i]) ans++;
}
for (int i = 1; i <= n; i++) c[i] = 0, vis[i] = 0;
printf("%d\n", ans);
}
return 0;
}
詳細信息
Test #1:
score: 5
Accepted
time: 2ms
memory: 12820kb
input:
10 17 50 1 3 1 10 1 5 3 7 10 2 7 8 7 6 8 9 9 4 5 7 5 10 2 10 6 5 8 2 7 2 2 6 2 3 8 7 1 8 2 1 3 2 3 9 9 1 10 5 3 5 10 3 9 6 5 2 2 8 6 2 4 5 5 4 10 7 2 7 1 9 7 5 9 3 5 9 3 8 7 10 4 1 7 9 1 2 6 8 3 1 4 6 4 7 7 4 10 1 9 8 5 1 1 7 4 2 8 1 8 5 1 4 10 4 5 8 3 6 8 10 6 1 3 10 6 4 6 3 9 10 4 9 8 3
output:
0 3 0 0 2 0 0 0 0 0 0 3 0 0 1 0 0 2 0 0 2 3 0 0 2 0 3 0 0 0 1 0 0 0 0 0 0 0 1 1 3 0 0 0 0 1 0 0 0 0
result:
ok 50 numbers
Test #2:
score: 5
Accepted
time: 2ms
memory: 12836kb
input:
10 20 50 1 3 3 10 3 5 5 7 7 2 2 8 8 6 8 9 9 4 10 3 7 10 8 7 10 2 2 7 7 3 2 6 4 6 2 10 6 9 10 7 3 2 3 1 1 4 5 8 7 1 4 3 7 5 9 10 5 3 1 6 10 8 6 2 9 3 2 1 2 4 9 6 9 1 6 5 7 8 4 5 6 8 3 7 4 10 4 2 4 9 7 6 7 9 1 8 5 1 8 5 8 1 3 4 8 2 5 4 5 6 8 4 9 5 10 6 9 8 8 3 10 4 5 10 1 2 10 1 6 3 6 4 5 9 6 7 6 10 1...
output:
0 0 3 4 0 0 0 0 0 3 4 0 0 0 1 0 0 0 4 0 0 0 0 0 0 3 3 7 0 0 0 3 0 3 3 1 0 3 0 0 3 0 7 0 0 1 3 0 0 0
result:
ok 50 numbers
Test #3:
score: 5
Accepted
time: 2ms
memory: 12932kb
input:
100 168 100 1 79 1 41 79 22 22 94 22 66 94 34 66 86 86 97 86 46 86 91 91 64 91 19 64 9 64 87 19 78 78 17 17 75 17 45 45 54 54 96 96 5 96 99 96 3 5 7 3 98 7 90 90 26 26 58 58 13 58 50 50 73 13 57 50 61 73 67 57 82 61 31 82 100 31 16 16 77 77 70 70 23 70 52 70 72 52 83 83 33 72 71 83 65 65 24 71 32 32...
output:
8 0 20 52 0 0 35 20 0 0 0 52 1 0 0 0 0 20 20 0 0 1 52 8 46 0 0 0 0 46 0 35 69 55 20 2 0 47 0 3 0 0 0 0 0 8 1 1 0 0 23 0 0 0 1 0 52 2 0 24 65 0 0 0 35 52 52 0 1 2 0 35 85 65 52 1 1 0 2 65 0 20 0 0 0 0 0 0 0 1 1 0 53 45 26 8 0 3 52 0
result:
ok 100 numbers
Test #4:
score: 5
Accepted
time: 0ms
memory: 12920kb
input:
100 169 100 1 79 79 41 79 22 41 94 22 66 94 34 66 86 66 97 86 46 86 91 46 64 64 19 19 9 9 87 87 78 78 17 87 75 75 45 45 54 54 96 54 5 96 99 96 3 99 7 99 98 7 90 98 26 90 58 58 13 58 50 50 73 73 57 57 61 57 67 57 82 67 31 82 100 82 16 31 77 100 70 77 23 70 52 52 72 52 83 52 33 72 71 71 65 33 24 71 32...
output:
17 1 0 71 0 0 39 87 0 3 0 1 0 5 0 1 0 1 0 0 69 0 0 3 61 53 2 1 0 72 0 1 24 68 45 0 4 0 46 68 21 18 0 17 61 0 55 27 53 3 2 1 69 0 0 21 21 0 0 3 0 0 1 0 0 1 0 45 0 1 0 53 0 4 0 0 0 0 1 2 0 13 39 0 0 0 39 1 1 0 0 0 0 1 1 46 2 61 0 39
result:
ok 100 numbers
Test #5:
score: 5
Accepted
time: 2ms
memory: 12980kb
input:
100 163 100 1 79 79 41 79 22 79 94 94 66 22 34 34 86 86 97 97 46 46 91 91 64 91 19 19 9 9 87 87 78 9 17 17 75 75 45 17 54 75 96 45 5 54 99 99 3 3 7 3 98 7 90 98 26 26 58 58 13 26 50 13 73 73 57 57 61 57 67 57 82 61 31 31 100 31 16 100 77 77 70 16 23 23 52 52 72 72 83 52 33 83 71 33 65 65 24 65 32 65...
output:
30 45 83 10 2 38 6 0 30 1 30 0 0 6 0 0 84 1 0 55 8 0 2 8 37 0 6 1 0 0 6 0 1 44 0 30 31 0 1 30 2 76 0 0 0 1 32 70 0 0 2 30 7 9 3 0 30 0 0 4 30 30 2 0 73 1 6 0 28 0 2 1 6 10 28 0 1 0 28 45 49 0 4 28 30 30 0 0 0 0 1 0 0 6 3 73 43 30 65 0
result:
ok 100 numbers
Test #6:
score: 5
Accepted
time: 2ms
memory: 12936kb
input:
100 167 100 1 79 1 41 1 22 22 94 22 66 94 34 34 86 34 97 34 46 86 91 46 64 91 19 19 9 9 87 19 78 87 17 78 75 78 45 45 54 45 96 96 5 5 99 99 3 3 7 7 98 3 90 7 26 26 58 58 13 13 50 50 73 13 57 73 61 57 67 57 82 82 31 31 100 82 16 100 77 77 70 77 23 70 52 70 72 23 83 52 33 33 71 71 65 33 24 65 32 65 89...
output:
34 48 0 1 0 29 1 0 1 1 0 12 0 33 29 9 0 0 1 0 0 0 0 0 33 44 0 0 0 29 0 24 45 1 35 3 0 89 1 1 0 2 1 2 71 0 9 0 24 2 48 0 45 12 51 44 1 29 12 0 44 44 0 30 33 12 29 1 29 1 29 29 44 3 0 0 29 1 44 1 0 3 0 46 0 9 9 1 0 0 77 0 0 1 1 1 12 0 61 0
result:
ok 100 numbers
Test #7:
score: 5
Accepted
time: 70ms
memory: 13068kb
input:
1000 999 20000 1 546 1 225 225 989 989 772 225 923 989 34 772 922 923 97 34 330 922 704 97 944 704 103 704 868 103 674 103 423 423 445 423 304 445 651 445 451 304 957 651 845 845 714 714 612 845 173 173 597 597 347 347 858 347 477 347 295 295 913 477 73 295 187 73 618 73 430 618 402 618 195 195 260 ...
output:
0 0 1 65 0 1 1 1 1 0 1 0 0 0 2 1 110 2 2 0 0 1 817 1 853 0 0 50 0 1 570 0 0 2 0 0 1 0 1 1 273 5 443 809 128 1 82 3 0 0 3 0 1 2 212 0 0 820 500 0 1 1 0 0 0 35 2 823 4 0 0 0 0 1 2 1 0 0 658 0 448 3 100 2 11 651 2 0 306 581 1 0 0 0 0 0 1 1 1 470 1 0 0 0 2 120 0 2 3 0 483 268 1 2 1 0 0 1 0 0 0 1 1 0 2 1...
result:
ok 20000 numbers
Test #8:
score: 5
Accepted
time: 65ms
memory: 13048kb
input:
1000 999 20000 1 471 1 84 1 391 391 990 990 735 990 907 735 375 375 979 979 650 375 496 979 679 650 440 679 748 679 643 440 469 643 927 469 461 927 788 461 158 158 634 634 672 158 139 139 610 139 154 139 323 323 426 323 784 426 203 784 945 945 1000 945 354 354 311 354 418 311 707 418 646 707 716 716...
output:
0 0 422 937 15 0 1 1 1 0 137 1 1 0 175 0 0 1 14 0 0 0 2 363 189 1 0 20 72 1 0 3 0 0 49 393 2 252 0 1 2 0 0 0 0 1 2 0 1 22 1 370 3 270 1 2 1 483 1 1 853 1 71 1 462 0 249 3 0 0 1 1 1 0 1 6 0 1 3 244 4 0 1 1 0 0 0 0 0 0 88 0 336 1 583 1 81 612 1 313 185 1 0 95 3 2 1 0 0 1 0 210 0 1 3 0 0 1 0 1 0 0 0 2 ...
result:
ok 20000 numbers
Test #9:
score: 5
Accepted
time: 65ms
memory: 12944kb
input:
1000 999 20000 1 38 1 467 1 846 467 668 846 85 85 465 465 815 815 350 465 329 815 18 329 380 329 822 380 156 156 793 793 139 793 134 793 487 139 396 396 571 571 835 571 607 607 427 427 525 525 140 525 474 474 994 474 16 474 419 16 558 558 946 946 630 558 862 946 142 862 964 142 605 142 765 964 901 7...
output:
1 460 2 154 0 971 612 2 551 193 0 55 3 0 1 1 0 0 557 0 0 0 0 0 0 0 88 0 709 0 403 1 2 0 2 0 351 1 674 1 56 2 0 0 86 0 0 5 0 494 0 2 4 154 1 1 0 0 3 217 0 0 0 1 781 0 741 0 61 0 0 359 1 0 697 0 0 0 3 5 0 1 1 2 411 3 0 0 1 404 215 0 138 0 0 0 0 2 2 0 0 1 0 0 0 426 0 168 563 1 0 2 1 1 0 2 0 359 1 148 1...
result:
ok 20000 numbers
Test #10:
score: 5
Accepted
time: 12ms
memory: 13004kb
input:
1000 2000 2000 1 951 1 616 1 527 616 383 616 620 383 93 93 139 620 382 93 372 372 364 372 678 372 978 364 891 678 828 828 853 828 276 853 226 853 702 226 589 226 833 702 213 833 899 899 171 899 920 899 16 16 434 434 247 434 62 62 234 247 600 234 900 900 889 900 807 900 948 889 430 430 198 948 681 43...
output:
92 1 0 92 342 0 0 1 0 0 136 92 2 705 317 0 278 0 491 64 555 0 804 7 0 224 0 2 0 0 94 705 92 504 274 1 613 0 120 0 167 0 196 0 313 653 653 265 0 160 92 0 491 313 730 0 160 92 94 653 714 0 22 242 1 305 440 1 0 0 440 0 705 0 0 242 1 0 0 0 1 0 0 1 375 0 653 265 242 596 807 0 1 0 0 216 0 0 1 0 274 0 504 ...
result:
ok 2000 numbers
Test #11:
score: 5
Accepted
time: 16ms
memory: 13020kb
input:
1000 2000 2000 1 951 951 616 616 527 616 383 527 620 383 93 93 139 93 382 139 372 382 364 372 678 678 978 364 891 978 828 891 853 828 276 276 226 853 702 276 589 589 833 833 213 833 899 833 171 171 920 171 16 920 434 920 247 16 62 62 234 234 600 234 900 600 889 600 807 807 948 889 430 948 198 430 68...
output:
0 2 789 0 0 0 243 590 68 137 741 1 0 407 0 284 0 1 668 145 0 158 454 40 563 0 0 684 629 243 193 0 1 0 0 905 2 2 0 642 746 491 222 228 1 454 424 290 0 2 2 373 454 0 251 1 34 60 0 271 88 335 627 0 1 1 545 407 1 323 1 1 491 250 0 324 0 454 238 0 1 138 391 407 0 0 0 0 98 116 599 491 0 0 0 642 454 2 454 ...
result:
ok 2000 numbers
Test #12:
score: 5
Accepted
time: 16ms
memory: 12912kb
input:
1000 2000 2000 1 951 1 616 616 527 951 383 616 620 527 93 93 139 139 382 139 372 372 364 382 678 372 978 678 891 978 828 891 853 853 276 276 226 276 702 702 589 702 833 702 213 833 899 899 171 899 920 920 16 16 434 434 247 16 62 434 234 247 600 62 900 234 889 889 807 807 948 948 430 430 198 198 681 ...
output:
184 0 1 729 155 36 0 389 389 568 112 0 2 0 0 698 0 3 0 410 800 146 1 698 153 511 0 0 0 201 285 854 0 1 1 767 255 0 442 36 639 36 0 590 90 0 0 0 36 228 255 1 123 0 1 2 0 0 209 1 0 0 555 0 97 511 159 698 585 698 0 744 0 0 36 114 0 0 1 0 0 0 0 1 112 1 77 1 1 585 1 419 0 0 1 0 639 1 1 543 410 0 1 77 0 1...
result:
ok 2000 numbers
Test #13:
score: 5
Accepted
time: 16ms
memory: 12980kb
input:
1000 2000 2000 1 951 951 616 1 527 527 383 616 620 620 93 620 139 620 382 382 372 382 364 364 678 678 978 978 891 678 828 828 853 891 276 828 226 853 702 226 589 702 833 833 213 589 899 213 171 171 920 171 16 171 434 16 247 247 62 434 234 247 600 234 900 600 889 889 807 889 948 807 430 948 198 430 6...
output:
0 848 1 94 256 113 142 30 370 0 634 341 115 0 43 0 0 1 1 276 43 255 30 443 174 129 0 0 1 418 142 142 4 0 167 403 101 0 513 480 237 513 2 0 584 119 438 0 0 370 94 1 0 0 532 0 221 255 371 0 0 218 418 0 388 403 1 0 1 113 438 0 0 0 904 3 0 0 0 0 120 19 724 307 0 0 296 3 0 1 0 0 0 403 306 0 1 1 119 341 5...
result:
ok 2000 numbers
Test #14:
score: 5
Accepted
time: 16ms
memory: 13028kb
input:
1000 2000 2000 1 951 1 616 1 527 951 383 527 620 383 93 93 139 620 382 139 372 372 364 382 678 364 978 364 891 678 828 828 853 828 276 828 226 853 702 226 589 702 833 702 213 589 899 833 171 213 920 920 16 920 434 920 247 247 62 247 234 234 600 62 900 234 889 600 807 889 948 889 430 948 198 430 681 ...
output:
174 242 0 0 0 720 527 527 1 2 176 0 0 0 0 538 0 0 0 0 396 1 377 0 207 0 0 527 0 0 0 622 375 0 374 0 0 2 0 0 0 0 1 0 1 0 242 538 0 263 0 418 0 396 837 0 0 0 0 0 417 0 559 71 71 680 49 0 0 345 19 2 0 1 631 71 0 622 0 0 0 0 0 0 71 79 0 202 801 174 29 0 1 1 292 0 0 0 2 0 71 744 0 720 106 292 0 377 1 1 1...
result:
ok 2000 numbers
Test #15:
score: 5
Accepted
time: 15ms
memory: 13004kb
input:
1000 2000 2000 1 951 951 616 1 527 951 383 383 620 383 93 620 139 139 382 93 372 139 364 372 678 364 978 364 891 891 828 978 853 828 276 276 226 226 702 226 589 702 833 702 213 213 899 899 171 899 920 899 16 920 434 16 247 434 62 434 234 62 600 600 900 234 889 900 807 900 948 948 430 430 198 430 681...
output:
79 0 164 1 0 582 2 1 56 127 0 0 0 0 2 0 1 184 642 1 4 0 325 1 0 0 2 1 639 153 0 0 347 0 0 427 967 107 0 76 0 291 0 0 180 0 0 0 0 223 0 0 2 239 1 312 79 676 377 0 0 1 78 559 121 0 1 901 122 0 165 7 2 0 39 0 0 2 0 68 1 7 0 155 803 0 0 276 232 0 267 665 1 0 68 107 0 0 0 483 0 1 178 0 559 836 0 561 1 0 ...
result:
ok 2000 numbers
Test #16:
score: 5
Accepted
time: 326ms
memory: 13112kb
input:
3000 6000 20000 1 2666 1 2279 1 60 2666 2780 60 684 60 2956 2780 211 684 1945 211 1016 1945 883 883 1739 1016 599 599 809 809 24 24 821 24 1253 1253 797 797 903 903 1651 1651 1674 1674 2482 2482 1635 1635 2405 2405 326 1635 253 2405 677 677 2937 677 2975 677 278 2937 1195 2975 99 99 1280 1280 1447 1...
output:
403 0 7 0 0 0 779 1 0 1 672 0 1 1777 0 1329 0 0 1 0 0 729 0 0 527 1219 1 1 700 0 851 1 0 0 0 215 596 1309 0 0 31 123 0 2 369 0 0 0 0 1309 0 1592 324 889 537 2 1 1189 1 1411 960 2188 0 0 6 1486 183 2611 0 298 1 0 0 1064 1449 894 1 97 4 2424 1 0 0 0 369 0 213 0 0 123 0 1 3 403 1 29 1449 0 0 968 0 0 50...
result:
ok 20000 numbers
Test #17:
score: 5
Accepted
time: 332ms
memory: 13192kb
input:
3000 6000 20000 1 212 1 2888 2888 2340 212 434 2340 468 434 620 468 730 468 1409 1409 1879 1409 399 399 534 1879 2259 2259 863 2259 1589 1589 516 1589 2266 516 2949 2266 2178 2178 1103 2178 323 1103 2376 323 2068 323 2860 2376 762 762 1231 2860 783 783 540 540 1159 783 2549 540 2609 1159 662 662 237...
output:
0 0 0 726 1296 0 107 134 0 1948 25 4 1 1879 790 1662 0 1 0 0 2083 0 504 0 545 0 740 0 1680 161 129 107 0 747 906 898 0 0 2633 809 0 0 237 2 1 2 0 0 0 1 1 1 47 0 1339 0 1 0 0 0 1054 1324 2 0 512 0 4 0 366 0 377 2 731 0 0 2061 0 757 2321 1 0 0 0 639 0 1324 0 3 366 0 261 2028 3 3 86 0 0 550 871 2359 0 ...
result:
ok 20000 numbers
Test #18:
score: 5
Accepted
time: 329ms
memory: 13184kb
input:
3000 6000 20000 1 1435 1 1469 1 2116 1435 1602 1469 659 1602 490 659 854 659 1303 1303 1160 1160 89 1160 564 89 840 840 2692 2692 1770 2692 2485 1770 328 328 1786 1786 63 328 1181 1786 2266 2266 1659 2266 2543 2543 2525 2543 1986 2525 1989 1986 2204 2204 2153 2204 930 2153 685 2153 218 218 2890 2890...
output:
365 3 292 1 1644 613 1 0 1 0 59 1310 1 1091 0 1311 0 2633 1197 0 378 0 0 0 0 3 0 1267 74 1 0 3 0 1152 149 1165 2 2 0 0 1 91 0 0 0 1238 0 0 1992 757 484 0 0 2521 814 332 0 0 199 1 0 0 773 711 0 0 0 324 1 714 792 0 0 1255 1267 267 0 2382 1 0 0 0 1267 0 1020 403 0 149 0 1 3 0 773 386 0 0 1 922 18 403 2...
result:
ok 20000 numbers
Test #19:
score: 5
Accepted
time: 332ms
memory: 13204kb
input:
3000 6000 20000 1 745 745 1630 1630 191 191 1149 191 114 1149 2270 2270 2602 114 2188 2188 307 307 882 307 1695 882 1021 1021 111 1021 816 816 491 111 1906 1906 2752 491 1332 2752 924 2752 2017 1332 1925 1925 1122 1925 159 1122 387 387 2336 159 188 188 986 986 1564 986 1236 1564 627 1564 1894 1236 1...
output:
1784 1953 541 0 27 0 1413 0 0 0 0 0 0 827 0 0 168 0 0 0 0 411 1 0 411 0 0 411 1 626 512 616 1 411 0 446 704 0 1 0 0 1 144 96 2021 0 1 1 689 0 0 1935 314 0 3 0 1275 0 0 0 332 590 96 0 1 1345 6 0 0 0 1 4 52 1613 1 431 1453 0 0 556 0 96 1714 1 0 1 2 0 2 633 1784 1341 0 0 0 2 0 0 2052 1129 0 0 0 0 626 1...
result:
ok 20000 numbers
Test #20:
score: 5
Accepted
time: 332ms
memory: 13016kb
input:
3000 6000 20000 1 1406 1 237 237 520 237 1841 520 2498 2498 13 13 2313 2498 180 13 425 180 574 574 2255 574 1417 574 288 2255 457 1417 988 288 2881 988 1145 1145 894 2881 351 351 1783 351 771 351 1609 1783 1739 771 2659 1609 2747 2659 1748 2747 2685 1748 2492 1748 2566 2492 1330 1330 1639 2566 530 1...
output:
0 701 2256 1 0 1439 327 1858 0 0 228 0 873 691 551 1818 0 807 0 301 0 1 0 894 0 1 0 0 0 159 0 551 0 405 1267 92 487 0 1974 0 5 2 2063 1 0 192 0 0 0 0 346 0 636 1 1 0 0 487 1702 1 0 0 1531 1911 0 0 0 221 1938 368 1 1615 0 3 551 0 1858 940 1540 1295 0 0 584 504 1 0 0 1267 1355 1413 2239 237 2149 1200 ...
result:
ok 20000 numbers
Extra Test:
score: 0
Extra Test Passed