QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#235086 | #6634. Central Subset | jzh# | AC ✓ | 107ms | 17076kb | C++20 | 1.7kb | 2023-11-02 13:39:52 | 2023-11-02 13:39:52 |
Judging History
answer
#include<bits/stdc++.h>
#include <vector>
#define range(x) begin(x), end(x)
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
int n, m;
cin >> n >> m;
vector<vector<int>> G(n + 1);
vector<int> fa(n + 1);
vector<int> deg(n + 1, 0);
for (int i = 1; i <= n; i++) {
fa[i] = i;
}
auto find = [&](int u) {
while (u != fa[u]) u = fa[u] = fa[fa[u]];
return u;
};
for (int i = 0; i < m; i++) {
int u, v;
cin >> u >> v;
if (find(u) != find(v)) {
fa[find(u)] = find(v);
G[u].push_back(v);
G[v].push_back(u);
deg[u]++, deg[v]++;
}
}
vector<int> dp(n + 1, 1);
queue<int> q;
for (int i = 1; i <= n; i++) {
if (deg[i] == 1) {
q.push(i);
}
}
vector<int> ans;
int lim = ceil(sqrt(n));
while (lim * lim < n)lim++;
while ((lim - 1) * (lim - 1) >= n) lim--;
while (!q.empty()) {
int u = q.front();
q.pop();
if (deg[u] == 0 || dp[u] >= lim) {
ans.push_back(u);
dp[u] = 0;
}
for (int v: G[u]) {
deg[v]--;
dp[v] += dp[u];
if (deg[v] == 1) {
q.push(v);
}
}
}
cout << ans.size() << "\n";
for(int u:ans){
cout << u <<" ";
}
cout << "\n";
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3532kb
input:
2 4 3 1 2 2 3 3 4 6 7 1 2 2 3 3 1 1 4 4 5 5 6 6 4
output:
2 2 3 2 1 4
result:
ok correct (2 test cases)
Test #2:
score: 0
Accepted
time: 18ms
memory: 3604kb
input:
10000 15 14 13 12 5 4 9 8 11 12 15 14 10 9 14 13 2 3 2 1 6 5 10 11 3 4 7 6 8 7 6 5 2 1 2 4 4 6 2 3 3 5 10 9 8 3 9 4 5 6 5 10 3 2 5 4 2 7 1 2 4 3 2 1 2 1 2 1 2 1 9 8 9 8 5 4 1 2 6 5 3 4 3 2 7 8 7 6 2 1 1 2 14 13 3 10 5 6 2 9 11 4 2 3 2 1 8 7 13 6 5 4 5 12 6 7 4 3 7 14 16 15 2 3 2 1 6 10 6 9 6 4 9 11 ...
output:
3 4 12 8 1 2 2 3 4 1 2 1 2 3 3 7 5 1 2 3 3 6 5 4 4 12 6 10 1 2 4 5 16 10 11 2 3 4 2 3 4 3 3 13 8 1 2 3 4 12 8 2 4 2 1 2 2 2 4 1 2 2 2 3 2 2 4 3 3 6 5 3 14 3 8 1 2 3 4 12 8 1 2 3 3 7 5 1 2 1 2 5 5 17 10 12 11 3 8 5 3 3 3 6 5 4 2 9 10 7 1 2 2 3 4 1 3 3 3 5 4 3 11 ...
result:
ok correct (10000 test cases)
Test #3:
score: 0
Accepted
time: 32ms
memory: 4040kb
input:
100 2000 1999 529 528 885 884 1221 1222 375 374 245 244 758 757 711 710 1521 1522 1875 1874 749 750 823 822 1959 1958 1767 1766 155 154 631 632 825 824 1330 1331 457 456 1344 1343 1817 1818 413 414 582 583 1828 1827 1335 1336 654 655 162 161 1668 1667 1966 1967 1472 1471 1185 1184 518 517 1509 1510 ...
output:
45 45 1956 90 1911 135 1866 180 1821 225 1776 270 1731 315 1686 360 1641 405 1596 450 1551 495 1506 540 1461 585 1416 630 1371 675 1326 720 1281 765 1236 810 1191 855 1146 900 1101 945 1056 990 1011 1001 36 57 56 78 48 36 171 99 113 91 117 41 106 38 158 60 14 134 98 43 143 59 222 135 4 55 32 19 49 ...
result:
ok correct (100 test cases)
Test #4:
score: 0
Accepted
time: 32ms
memory: 4976kb
input:
10 14914 14913 13959 13958 3643 3642 4582 4581 13378 13379 981 980 12901 12902 12355 12356 14692 14691 9670 9669 14632 14631 1441 1440 1367 1368 6237 6238 8297 8298 1021 1020 5096 5097 4773 4774 7778 7779 3013 3014 5536 5535 11621 11620 13904 13903 3050 3049 14179 14178 7471 7472 13380 13381 7403 74...
output:
121 123 14792 246 14669 369 14546 492 14423 615 14300 738 14177 861 14054 984 13931 1107 13808 1230 13685 1353 13562 1476 13439 1599 13316 1722 13193 1845 13070 1968 12947 2091 12824 2214 12701 2337 12578 2460 12455 2583 12332 2706 12209 2829 12086 2952 11963 3075 11840 3198 11717 3321 11594 3444 11...
result:
ok correct (10 test cases)
Test #5:
score: 0
Accepted
time: 40ms
memory: 5016kb
input:
10 20000 19999 6831 6760 15763 15900 10362 10184 5821 5880 17555 17389 16708 16574 11592 11436 186 209 19380 19313 8867 8718 12100 12237 16245 16110 18464 18568 4713 4665 17412 17578 18666 18750 4360 4322 12350 12502 4054 4103 2874 2849 8097 8202 14489 14639 1056 1016 13500 13581 2435 2391 199 173 8...
output:
119 846 5719 9372 10406 9211 15696 215 5681 5745 13210 17714 5705 6570 18730 997 7533 7942 9509 10708 14286 15586 16179 13 8696 10328 16151 17844 11286 11642 14537 15633 13960 18694 2850 4184 9832 17467 19287 6410 12698 3898 9205 11292 1266 9476 7248 14693 87 4808 14797 15870 4549 10243 14557 13576 ...
result:
ok correct (10 test cases)
Test #6:
score: 0
Accepted
time: 48ms
memory: 16380kb
input:
1 200000 199999 136649 136648 44943 44944 7148 7149 50332 50333 149967 149966 28976 28975 78549 78550 178698 178697 96434 96433 7859 7858 88976 88977 23348 23347 161682 161681 125393 125392 67892 67893 73592 73593 179054 179055 110841 110842 163714 163715 7982 7981 56309 56310 196486 196485 19176 19...
output:
447 448 199553 896 199105 1344 198657 1792 198209 2240 197761 2688 197313 3136 196865 3584 196417 4032 195969 4480 195521 4928 195073 5376 194625 5824 194177 6272 193729 6720 193281 7168 192833 7616 192385 8064 191937 8512 191489 8960 191041 9408 190593 9856 190145 10304 189697 10752 189249 11200 18...
result:
ok correct (1 test case)
Test #7:
score: 0
Accepted
time: 44ms
memory: 17076kb
input:
1 200000 199999 58280 58281 132016 32016 45157 45158 35446 35445 158979 58979 185831 85831 74289 174289 195645 95645 31857 131857 168766 68766 95607 95606 39817 39818 58215 158215 74893 74894 18897 118897 63013 163013 58501 58502 94475 194475 77574 77573 152977 52977 3731 103731 20407 20408 186570 8...
output:
447 225 99777 449 99553 673 99329 897 99105 1121 98881 1345 98657 1569 98433 1793 98209 2017 97985 2241 97761 2465 97537 2689 97313 2913 97089 3137 96865 3361 96641 3585 96417 3809 96193 4033 95969 4257 95745 4481 95521 4705 95297 4929 95073 5153 94849 5377 94625 5601 94401 5825 94177 6049 93953 627...
result:
ok correct (1 test case)
Test #8:
score: 0
Accepted
time: 53ms
memory: 16788kb
input:
1 200000 199999 84088 84001 74829 74679 40726 41179 113019 113238 112813 113025 77336 77177 60908 61208 4521 4639 144249 144094 102763 102692 112856 113070 2428 2356 114005 113754 168454 168270 114538 114311 36802 36341 170182 170306 31641 32012 92503 92395 143570 143702 6871 6715 51503 51997 140883...
output:
381 185213 64161 79840 64807 100028 24417 67344 105129 107369 157583 6995 87453 74469 51220 142622 155669 193804 13696 71455 109825 126901 162796 196174 24323 49476 75368 155878 2063 5552 84019 90146 116551 125724 142113 143497 158105 164528 164628 182185 42785 137086 154603 89563 97563 120107 13694...
result:
ok correct (1 test case)
Test #9:
score: 0
Accepted
time: 12ms
memory: 3892kb
input:
1000 11 19 8 11 4 11 2 11 2 3 8 3 6 1 6 4 11 5 5 3 10 8 7 10 4 7 3 9 5 1 5 7 3 6 10 1 11 7 2 9 70 109 32 69 26 15 65 46 70 62 50 23 17 16 15 31 2 23 18 11 48 57 19 29 52 42 26 31 7 1 53 66 5 69 58 20 59 38 3 4 9 53 7 56 52 66 66 28 22 51 2 6 22 35 5 28 25 51 27 13 26 56 10 50 53 56 60 48 67 33 61 23...
output:
1 11 6 2 38 56 5 52 66 3 23 16 5 8 66 76 44 2 54 39 57 89 6 4 39 42 30 35 36 3 2 13 15 6 13 44 12 21 24 32 6 2 17 18 32 45 41 7 47 2 68 66 49 38 56 7 36 76 11 75 46 40 31 5 2 5 21 7 10 8 92 93 78 34 56 63 61 32 1 2 6 16 8 13 11 17 37 6 11 14 12 6 20 24 4 5 16 3 11 3 8 12 18 1 3 7 3...
result:
ok correct (1000 test cases)
Test #10:
score: 0
Accepted
time: 2ms
memory: 3636kb
input:
100 76 104 30 11 26 40 4 59 35 21 13 44 3 73 25 39 33 35 63 9 9 19 42 47 22 32 44 35 74 68 53 12 50 41 53 52 69 40 31 49 21 14 23 21 11 48 53 67 48 74 15 24 73 47 6 62 17 33 67 48 7 22 68 46 41 39 20 1 9 71 15 67 65 56 38 68 30 9 54 26 8 47 62 56 14 61 59 20 46 64 75 46 50 49 26 25 10 70 36 27 14 29...
output:
8 7 62 76 26 67 21 30 63 7 46 40 52 50 54 64 4 5 49 37 38 1 19 7 3 32 27 44 40 42 43 7 37 49 20 63 23 57 54 6 24 11 53 37 30 48 6 2 6 48 50 46 27 5 43 26 46 48 49 7 2 20 37 61 48 69 19 5 21 14 8 11 15 7 5 1 42 44 23 21 80 9 71 29 85 34 7 52 37 28 32 8 36 27 25 10 77 32 64 69 7 17 54 2 1...
result:
ok correct (100 test cases)
Test #11:
score: 0
Accepted
time: 107ms
memory: 9928kb
input:
1 100000 1000000 70376 68374 69858 95507 48028 59467 27775 34161 858 86059 31468 25048 21313 82671 10952 18093 89665 50624 52742 11128 33566 41507 25913 22268 72131 67543 31387 42274 37347 75248 88261 56182 98982 47735 90574 62875 51228 53905 25218 4567 78201 22017 59613 68982 37239 43727 67620 9064...
output:
261 27848 68965 28635 7863 21945 32818 83945 32251 49294 62072 33526 9696 85778 7451 95959 8658 57497 15488 57301 79020 51397 53425 43311 3735 41198 45267 87411 6976 60688 89337 47878 26522 19105 3498 40779 91470 80899 9677 39899 7563 22091 32162 973 6103 88052 53414 60646 16633 41441 84850 44042 98...
result:
ok correct (1 test case)
Test #12:
score: 0
Accepted
time: 52ms
memory: 16452kb
input:
1 200000 200000 89381 101645 141954 180063 180085 158544 12185 82120 161570 175869 36911 151360 49966 148400 135100 143084 145185 33970 82150 111213 93727 145916 42620 157053 26848 66273 178649 76101 5033 162413 173225 34259 30781 78979 9908 187256 87177 127185 7086 26040 178611 119947 198142 154140...
output:
447 84112 112925 148894 183372 153043 78381 27629 25042 7504 132361 156431 36833 72380 6965 45269 106125 91029 82250 36727 61677 49526 127868 56082 184669 97111 76026 94858 1239 2613 105793 102968 170062 123789 72979 9026 170906 54289 84218 68452 95441 593 138664 125714 2593 114570 80229 22393 12260...
result:
ok correct (1 test case)
Test #13:
score: 0
Accepted
time: 38ms
memory: 16428kb
input:
1 199809 199808 197381 136472 136472 160228 160228 128766 128766 197225 197225 160133 160133 105707 105707 66465 66465 199512 199512 185463 185463 176514 176514 175293 175293 178768 178768 158873 158873 199518 199518 161400 161400 172476 172476 188761 188761 197795 197795 152286 152286 177332 177332...
output:
447 19109 19008 69723 33723 87787 84439 17900 18252 43576 94598 38460 28939 29197 6854 38747 14272 18195 19390 70331 50237 43394 18707 19721 1309 145491 49080 61969 6911 30153 77582 81280 28066 59998 6121 2918 13465 85 34286 36317 36402 32263 179478 78396 96397 26170 67195 49502 24473 37788 28218 52...
result:
ok correct (1 test case)
Test #14:
score: 0
Accepted
time: 39ms
memory: 3656kb
input:
200 961 1663 2 1 3 1 3 20 4 1 4 7 5 1 5 41 5 60 6 1 7 1 7 49 8 1 9 1 10 1 11 1 12 1 12 32 13 1 13 59 14 1 14 3 15 1 15 12 15 52 16 1 16 12 16 63 17 1 17 10 18 1 18 36 19 1 19 26 19 29 20 1 20 60 20 63 21 1 22 1 23 1 23 3 23 27 23 39 24 1 25 1 26 1 26 58 26 60 27 1 27 22 27 36 28 1 29 1 30 1 31 1 31 ...
output:
23 756 759 778 375 711 65 33 528 216 502 598 223 596 540 552 328 361 336 222 261 171 35 1 24 296 753 740 222 642 800 251 539 472 584 661 523 90 452 384 461 254 119 43 169 44 154 1 39 21 282 470 776 686 721 332 535 655 8 2 5 604 605 540 316 443 378 293 208 191 1 22 808 781 259 107 411 650 257 659 ...
result:
ok correct (200 test cases)
Test #15:
score: 0
Accepted
time: 27ms
memory: 13908kb
input:
1 160000 159999 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50 51 5...
output:
3 400 802 1
result:
ok correct (1 test case)
Test #16:
score: 0
Accepted
time: 31ms
memory: 3880kb
input:
1 1000 499500 605 964 559 738 492 518 943 284 96 23 214 486 487 262 347 436 394 422 270 113 984 149 134 203 881 328 316 643 610 922 802 67 903 194 600 584 629 62 692 370 420 442 600 563 438 452 556 785 112 809 555 241 937 635 178 746 67 900 777 247 490 842 971 12 315 60 703 467 201 13 872 503 24 201...
output:
26 539 134 67 11 824 922 722 563 161 821 658 105 874 994 809 640 537 492 685 834 940 370 319 201 913 686
result:
ok correct (1 test case)
Test #17:
score: 0
Accepted
time: 30ms
memory: 3884kb
input:
4081 49 48 39 7 7 45 45 25 25 31 31 26 26 4 4 11 4 19 4 37 4 8 4 16 4 22 4 33 11 14 39 6 6 12 12 46 46 49 49 48 48 29 29 27 39 41 41 15 15 34 34 24 39 3 3 13 13 20 20 47 39 9 9 36 36 5 5 43 39 40 40 21 21 2 2 38 39 35 35 42 42 23 23 28 39 1 1 32 32 10 10 17 39 30 30 18 18 44 49 48 37 29 29 33 33 19 ...
output:
3 4 6 39 4 48 44 37 29 3 23 11 9 3 2 18 43 4 23 2 16 37 4 33 23 43 46 3 49 36 30 3 47 7 34 4 17 19 21 39 4 38 2 27 11 3 18 39 43 4 6 18 19 7 3 22 46 28 4 13 48 14 6 4 21 41 44 30 4 22 46 5 17 3 33 30 37 3 44 42 4 4 45 6 8 44 4 2 29 30 9 4 43 41 23 8 3 32 20 21 3 21 28 19 4 5 1...
result:
ok correct (4081 test cases)