QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#870263 | #6144. 支配 | juruoA | 30 | 2ms | 6544kb | C++11 | 5.8kb | 2025-01-25 15:36:04 | 2025-01-25 15:36:11 |
Judging History
answer
#pragma GCC optimized("Ofast")
#include <bits/stdc++.h>
using std::bitset;
using std::cout;
using std::deque;
using std::endl;
using std::greater;
using std::lower_bound;
using std::make_pair;
using std::map;
using std::max;
using std::min;
using std::multimap;
using std::multiset;
using std::nth_element;
using std::pair;
using std::priority_queue;
using std::queue;
using std::reverse;
using std::set;
using std::sort;
using std::sqrt;
using std::stable_sort;
using std::string;
using std::swap;
using std::unique;
using std::upper_bound;
using std::vector;
typedef int li;
typedef long double lf;
inline li read(){
long long ans = 0, f = 1;
char ch = getchar();
while(ch < '0' || ch > '9'){
f = (ch == '-') ? -1 : 1;
ch = getchar();
}
while(ch <= '9' && ch >= '0'){
ans = ans * 10 + (ch ^ 48);
ch = getchar();
}
return ans * f;
}
li n, m, Q, vis[3010], fa[3010], h[3010];
vector<li> g[3010];
set<li> b[3010];
li head[3010], lenedge, Head[3010];
struct node{
li to, next;
} a[6010], B[6010];
void addedge(li u, li v){
a[++lenedge] = {v, head[u]};
head[u] = lenedge;
}
namespace bf{
li size[3010], vis2[3010];
vector<li> c[3010];
li mp[3010][3010];
void bfs(li u){
queue<li> q;
q.push(vis[u] = 1);
while(q.size()){
li u = q.front();
q.pop();
for(li i = head[u]; i; i = a[i].next){
if(!vis[a[i].to]){
vis[a[i].to] = 1;
q.push(a[i].to);
}
}
}
}
void pre(){
for(li i = 2; i <= n; i++){
for(li j = 2; j <= n; j++) vis[j] = 0;
vis[i] = 1;
bfs(1);
for(li j = 2; j <= n; j++){
if(!vis[j]) b[j].insert(i), vis2[i] = 1, c[i].push_back(j), mp[i][j] = 1;
}
}
}
li FL;
void dfs(li i){
// cout << "i = " << i << endl;
// if(g[i].size() == 0) return;
if(FL && h[i] == 2) return;
if(h[i] == 1) return;
for(li j = 2; j <= n; j++) vis[j] = 0;
vis[i] = 1;
bfs(1);
li fl = 1;
for(li j = 2; j <= n; j++){
if(mp[i][j] != (!vis[j])){
size[j] = 1;
fl = 0;
FL = 1;
}
}
// cout << i << " " << fl << endl;
if(!fl) return;
for(li v : g[i]){
dfs(v);
}
}
void work(){
// for(li i = 1; i <= n; i++, printf("\n")){
// for(li v : b[i]) printf("%lld ", v);
// }
for(li i = 1; i <= n; i++) Head[i] = head[i];
for(li i = 1; i <= lenedge; i++) B[i] = a[i];
while(Q--){
FL = 0;
li u = read(), v = read();
// a[u].push_back(v);
for(li i = 1; i <= n; i++) head[i] = Head[i];
for(li i = 1; i <= lenedge; i++) a[i] = B[i];
addedge(u, v);
li FL = 0;
for(li i = 2; i <= n; i++) size[i] = 0;
// for(li i = 1; i <= n; i++){
// if(h[i] == 2){
// for(li j = 2; j <= n; j++) vis[j] = 0;
// vis[i] = 1;
// bfs(1);
// li fl = 1;
// for(li j = 2; j <= n; j++){
// if(mp[i][j] != (!vis[j])){
// size[j] = 1;
// fl = 0;
// FL = 1;
// }
// }
// }
// }
// if(!FL){
// a[u].pop_back();
// printf("0\n");
// continue;
// }
// if(b[v].size() == 0){
// printf("0\n");
// continue;
// }
dfs(1);
li ans = 0;
for(li i = 2; i <= n; i++){
// cout << size[i] << " " << b[i].size() << endl;
if(size[i]) ans++;
}
printf("%d\n", ans);
lenedge--;
// a[u].pop_back();
}
exit(0);
}
}
void dfs2(li u){
for(li v : g[u]){
dfs2(v);
h[u] = max(h[u], h[v]);
}
h[u]++;
}
int main(){
// freopen("wonderful.ans", "r", stdin);
// freopen("www.ww", "w", stdout);
// freopen("dominator.in", "r", stdin);
// freopen("dominator.out", "w", stdout);
n = read(), m = read(), Q = read();
for(li i = 1; i <= m; i++){
li u = read(), v = read();
// a[u].push_back(v);
addedge(u, v);
}
bf::pre();
for(li i = 2; i <= n; i++) b[i].insert(1);
// for(li i = 1; i <= n; i++, cout << endl) for(li v : b[i]) cout << v << " ";
// for(li i = 2; i <= n; i++) b[i].erase(i);
memset(vis, 0, sizeof vis);
for(li C = 1; C <= n; C++){
li minn = 0, size = 1e9;
for(li i = 1; i <= n; i++){
if(b[i].size() < size && !vis[i]){
minn = i, size = b[i].size();
}
}
assert(size <= 1);
vis[minn] = 1;
if(size == 1){
li u = *b[minn].begin();
g[fa[minn] = u].push_back(minn);
for(li j = 1; j <= n; j++){
if(!vis[j]){
if(b[j].find(u) != b[j].end() && b[j].find(minn) != b[j].end()) b[j].erase(u);
}
}
}
}
// cout << endl;
// for(li i = 1; i <= n; i++) for(li v : g[i]){
// if(g[v].size()) cout << i << " " << v << " " << bf::mp[i][v] << " " << bf::mp[v][i] << endl;
// }
dfs2(1);
// for(li i = 1; i <= n; i++) if(h[i] == 2) cout << "i = " << i << endl;
bf::work();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Pretests
Final Tests
Test #1:
score: 5
Accepted
time: 1ms
memory: 3840kb
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: 0ms
memory: 6172kb
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: 4480kb
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: 1ms
memory: 4352kb
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: 4480kb
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: 1ms
memory: 6544kb
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: 0
Time Limit Exceeded
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:
result:
Test #8:
score: 0
Time Limit Exceeded
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:
result:
Test #9:
score: 0
Time Limit Exceeded
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:
result:
Test #10:
score: 0
Time Limit Exceeded
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:
result:
Test #11:
score: 0
Time Limit Exceeded
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:
result:
Test #12:
score: 0
Time Limit Exceeded
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:
result:
Test #13:
score: 0
Time Limit Exceeded
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:
result:
Test #14:
score: 0
Time Limit Exceeded
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:
result:
Test #15:
score: 0
Time Limit Exceeded
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:
result:
Test #16:
score: 0
Time Limit Exceeded
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:
result:
Test #17:
score: 0
Time Limit Exceeded
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:
result:
Test #18:
score: 0
Time Limit Exceeded
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:
result:
Test #19:
score: 0
Time Limit Exceeded
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:
result:
Test #20:
score: 0
Time Limit Exceeded
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...