QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#930790 | #8873. Keys | AngelOlan | AC ✓ | 67ms | 41912kb | C++23 | 3.6kb | 2025-03-10 10:46:23 | 2025-03-10 10:46:23 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
// Pura Gente del Coach Moy y de la Alexbriza
void dfs(int u, vector<vector<pair<int, int>>>& g, vector<pair<int, int>>& p, vector<bool>& inPath, vector<bool>& vis) {
if (!u) {
inPath[u] = true;
}
vis[u] = true;
for (auto [v, i] : g[u]) {
if (!vis[v]) {
p[v] = make_pair(u, i);
dfs(v, g, p, inPath, vis);
if (inPath[v]) {
inPath[u] = true;
}
}
}
}
void calc(vector<vector<pair<int, int>>>& g, vector<pair<int, int>>& p, vector<bool>& inPath) {
vector<bool> vis(int(g.size()));
dfs(1, g, p, inPath, vis);
}
vector<int> keysUpTo(int u, int v, vector<pair<int, int>>& p) {
vector<int> ret;
while (u != v) {
ret.push_back(p[u].second);
u = p[u].first;
}
return ret;
}
vector<string> pathUpTo(int u, int v, vector<pair<int, int>>& p) {
vector<string> ret;
while (u != v) {
ret.push_back("MOVE " + to_string(p[u].first));
u = p[u].first;
}
return ret;
}
vector<string> pathDownTo(int u, int v, vector<pair<int, int>>& p) {
swap(u, v);
vector<string> ret;
while (u != v) {
ret.push_back("MOVE " + to_string(u));
u = p[u].first;
}
reverse(ret.begin(), ret.end());
return ret;
}
string listedKeysUpTo(int u, int v, vector<pair<int, int>>& p) {
string ret = "";
while (u != v) {
if (!ret.empty()) {
ret += " ";
}
ret += to_string(p[u].second);
u = p[u].first;
}
return ret;
}
template <typename T>
void add(vector<T>& a, vector<T> b) {
for (T& x : b) {
a.push_back(x);
}
}
int main() {
cin.tie(0)->sync_with_stdio(0);
int n, m;
cin >> n >> m;
vector<vector<pair<int, int>>> g(n);
for (int i = 0; i < m; ++i) {
int u, v;
cin >> u >> v;
g[u].emplace_back(v, i);
g[v].emplace_back(u, i);
}
vector<pair<int, int>> p(n);
vector<bool> inPath(n);
calc(g, p, inPath);
pair<int, int> backEdge = {-1, -1};
for (auto [v, i] : g[1]) {
if (p[v].first != 1) {
backEdge = make_pair(v, i);
break;
}
}
if (backEdge.first == -1) {
cout << "No solution\n";
return 0;
}
int lca = backEdge.first;
while (lca != 1 && !inPath[lca]) {
lca = p[lca].first;
}
vector<int> ak, bk;
vector<string> moves;
ak = keysUpTo(0, 1, p);
bk.push_back(backEdge.second);
if (!lca) {
add(bk, keysUpTo(backEdge.first, 0, p));
moves = pathUpTo(0, 1, p);
moves.push_back("DONE");
moves.push_back("MOVE " + to_string(backEdge.first));
add(moves, pathUpTo(backEdge.first, 0, p));
moves.push_back("DONE");
} else if (lca != 1 && inPath[lca]) {
add(bk, keysUpTo(backEdge.first, lca, p));
moves = pathUpTo(0, lca, p);
moves.push_back("DROP " + listedKeysUpTo(0, lca, p));
add(moves, pathUpTo(lca, 1, p));
moves.push_back("DONE");
moves.push_back("MOVE " + to_string(backEdge.first));
add(moves, pathUpTo(backEdge.first, lca, p));
moves.push_back("GRAB");
add(moves, pathDownTo(lca, 0, p));
moves.push_back("DONE");
} else {
add(ak, keysUpTo(backEdge.first, 1, p));
add(moves, pathUpTo(0, 1, p));
add(moves, pathDownTo(1, backEdge.first, p));
moves.push_back("DROP " + listedKeysUpTo(0, 1, p));
add(moves, pathUpTo(backEdge.first, 1, p));
moves.push_back("DONE");
moves.push_back("MOVE " + to_string(backEdge.first));
moves.push_back("GRAB");
moves.push_back("MOVE 1");
add(moves, pathDownTo(1, 0, p));
moves.push_back("DONE");
}
for (int x : ak) {
cout << x << ' ';
}
cout << '\n';
for (int x : bk) {
cout << x << ' ';
}
cout << '\n';
for (auto x : moves) {
cout << x << '\n';
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 27ms
memory: 11572kb
input:
100000 100000 23318 40203 97982 61157 60398 86095 58324 78522 28830 15221 65885 58978 88701 79733 60488 97069 18196 67504 53341 92581 41374 31350 38622 72661 83410 44870 47326 8073 98347 37592 6260 85798 28852 71221 50180 3244 64489 93594 78096 7442 17696 59981 22755 17291 17870 81187 35524 29465 22...
output:
79882 28282 23930 24038 59588 89803 38544 59873 97521 67560 46053 57861 26734 53864 80860 39595 25619 17206 63916 63489 45581 36129 3400 32111 64372 91046 77828 27213 88488 35 76393 20406 85327 92977 83517 42700 39535 94570 15902 70479 82243 50382 30004 7756 18448 97240 53281 20442 87660 89033 67647...
result:
ok good job, 10323 instruction(s)
Test #2:
score: 0
Accepted
time: 35ms
memory: 15840kb
input:
50000 100000 8934 28735 44226 12238 17786 15795 13217 27239 168 16295 550 15556 16441 41473 36979 35662 5444 33264 26116 48547 32991 35682 15764 44379 12428 45701 47650 4749 32595 21554 40428 36364 41567 14621 3849 33959 43468 46279 48666 11408 3325 20704 25461 14749 47526 49245 33711 19577 13605 43...
output:
46156 1474 64439 52028 45389 19237 80624 65877 51689 57724 56953 32266 48126 43503 30691 73017 6444 33217 1504 35967 45383 97276 26917 2819 16445 3797 70804 32274 79543 40682 92434 97161 11346 42284 36420 14402 45709 98845 18723 49952 48721 17804 16106 16358 56349 49330 19126 74020 72312 50821 75007...
result:
ok good job, 46576 instruction(s)
Test #3:
score: 0
Accepted
time: 64ms
memory: 36044kb
input:
100000 100000 25942 82376 88672 78819 18680 79879 67017 29864 43795 42855 7573 47211 33582 81171 12735 62529 65617 20494 99853 41155 78124 82179 38806 81035 57275 6802 50707 33443 33953 4519 91953 55970 59249 62761 48557 65743 71493 80407 90878 54712 66231 20900 21622 66923 94531 11951 54879 92804 5...
output:
69037 12659 39101 78989 32531 51220 56192 31085 31048 27730 10784 40130 89268 19707 36774 45512 53455 80522 90429 64748 44483 39820 46101 301 20660 89200 81583 21765 64520 8684 83776 41998 92574 68579 88777 55870 77023 81326 18482 16038 87286 68216 50326 77942 70313 95426 5883 90165 23767 75370 3293...
result:
ok good job, 150002 instruction(s)
Test #4:
score: 0
Accepted
time: 61ms
memory: 41912kb
input:
100000 100000 21864 56883 52947 45601 74935 69509 94478 26883 4033 18901 13136 47602 57282 96987 1689 58102 77156 35075 95629 47175 5915 19979 71495 48121 91235 85213 69319 43824 88116 6683 42155 72450 15251 23971 28359 85564 88246 94015 27333 69498 26663 81965 31007 91728 69773 34777 42347 72107 89...
output:
73662 57929 46494 61288 87362 50656 81972 42581 66119 18303 12230 16461 82010 52336 46846 68932 32850 68361 56130 80830 15911 70267 43021 1735 50706 40987 94076 2103 92670 79476 37184 37113 70604 64105 53445 71021 2816 41829 76484 31624 78801 69327 52726 14550 31214 56637 51853 85981 9404 59179 9099...
result:
ok good job, 199997 instruction(s)
Test #5:
score: 0
Accepted
time: 55ms
memory: 35016kb
input:
100000 100000 1579 36634 55021 87121 61247 53504 26526 11501 63096 95355 26157 54097 22547 72337 53502 93653 10336 58493 18020 41208 7269 2318 12039 94961 70947 16210 46822 1274 33785 1813 10779 40529 77491 71330 9272 95406 36277 69039 33374 7524 83196 20806 96206 89860 86304 59579 95435 52196 80968...
output:
35934 6179 88664 84854 21286 28562 90455 97383 59142 32220 95633 99696 70715 54475 77918 33964 99149 18041 5801 84044 60736 42652 54812 76965 87472 6992 73842 99147 30023 10070 31288 6878 14507 94291 73871 89669 69944 49483 94370 85093 18995 97838 62994 12926 80491 80270 89044 82763 45185 96781 8836...
result:
ok good job, 100012 instruction(s)
Test #6:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
6 6 0 2 2 3 3 1 3 4 4 5 1 5
output:
0 1 2 5 4 3 MOVE 2 MOVE 3 DROP 0 1 MOVE 1 DONE MOVE 5 MOVE 4 MOVE 3 GRAB MOVE 2 MOVE 0 DONE
result:
ok good job, 12 instruction(s)
Test #7:
score: 0
Accepted
time: 1ms
memory: 3712kb
input:
6 6 0 2 2 3 3 1 1 4 4 5 1 5
output:
0 1 2 4 3 5 MOVE 2 MOVE 3 MOVE 1 MOVE 4 MOVE 5 DROP 0 1 2 MOVE 4 MOVE 1 DONE MOVE 5 GRAB MOVE 1 MOVE 3 MOVE 2 MOVE 0 DONE
result:
ok good job, 16 instruction(s)
Test #8:
score: 0
Accepted
time: 35ms
memory: 12648kb
input:
100000 100000 96367 66531 65295 71645 67296 93287 73673 40112 15826 61132 89088 31681 50727 38751 7202 84213 59585 77793 48336 3706 17614 32412 6411 36116 80130 50904 81086 20756 69676 50485 46054 28686 16875 11587 91878 86414 12128 41724 69733 78314 87279 80436 57326 95934 26572 60051 2769 85752 15...
output:
1870 83734 49164 54697 89174 97868 40983 23521 77357 16077 97311 21147 97941 9099 13299 32003 65956 99360 25372 11555 86158 36146 92928 9981 68856 82209 73126 92993 62138 20886 2585 41726 24643 28183 49336 16456 17517 41792 31865 60633 99553 42452 20108 4904 1887 53898 36168 42112 66076 58015 71196 ...
result:
ok good job, 12520 instruction(s)
Test #9:
score: 0
Accepted
time: 54ms
memory: 30780kb
input:
100000 100000 10014 30317 91383 38616 44018 69738 67567 14439 94645 77295 40683 36981 93253 77191 86464 17901 9306 64146 77493 92538 73062 26034 41936 5045 43534 12176 81788 12494 51574 64920 79813 936 81999 67801 60001 96187 61237 45643 81878 58084 41735 16898 11958 65746 51947 96855 72637 87194 71...
output:
59181 11330 26220 96664 3624 17488 21845 45095 64555 26741 9575 89261 86609 72635 66159 90429 20487 23382 93458 41096 86366 47147 25869 33348 6793 66766 16436 16378 35569 97820 56497 81152 66461 60066 21904 27705 79746 20469 13261 39722 17910 97099 48848 62668 13966 68916 44260 2293 164 91436 81893 ...
result:
ok good job, 100002 instruction(s)
Test #10:
score: 0
Accepted
time: 27ms
memory: 16268kb
input:
50000 100000 24539 6119 20751 35924 41982 48393 19912 32252 10409 28344 16342 33219 1887 8519 21267 26408 8705 10970 2657 17850 39993 2645 512 27373 15091 23151 12486 45982 48476 4490 25329 15083 7662 42457 3308 3722 4529 42388 24030 42893 24228 9162 38184 41052 9096 16089 4324 11034 26951 33431 270...
output:
53070 27644 36593 73254 43781 31076 36437 39066 31858 14823 6854 21347 7892 91268 10920 41120 40194 86362 23569 83595 38863 41389 21186 93223 49950 37807 29572 26556 82681 51258 38556 95859 21870 82813 2103 34474 80466 87947 98479 31733 62823 40954 6780 4739 29229 45675 34179 9348 58221 41281 40930 ...
result:
ok good job, 35317 instruction(s)
Test #11:
score: 0
Accepted
time: 37ms
memory: 15860kb
input:
100000 100000 43296 75273 85441 62496 89990 49908 73020 129 55990 71803 84461 36667 88524 92277 57523 90585 61215 94569 67755 68868 12382 91067 84640 1421 10362 56957 54388 15787 98562 57954 57458 7730 90559 76725 10535 67001 37969 90538 63009 83781 33040 174 28995 25391 42150 72884 48377 68701 7704...
output:
47600 66493 50254 63715 20660 1825 42358 88658 50613 52242 4937 11026 62081 17635 54128 64063 49018 95582 23423 1136 63997 69322 34852 30368 88364 99591 72881 23581 67586 46058 54022 52634 14873 40586 17243 85495 48960 46991 85363 29733 72253 91364 89530 81655 58185 15984 29553 79904 41300 62596 622...
result:
ok good job, 42180 instruction(s)
Test #12:
score: 0
Accepted
time: 33ms
memory: 12072kb
input:
50000 100000 7568 36646 1279 47292 45650 35409 46841 16671 47440 40391 27528 17631 10548 26844 23545 14620 14511 23071 13025 37478 1923 48560 6122 30106 28548 36103 9215 36285 37710 44617 3674 49875 14022 16799 44476 30381 33114 30895 41787 37779 19820 47557 7937 4087 2576 2981 19278 36043 6340 3419...
output:
62678 10154 13557 41848 5601 9502 65426 902 21396 55679 34482 26050 12707 43366 8439 11393 5558 13627 35813 17864 36875 54504 20535 25578 5285 8617 3266 9420 4561 9262 10741 6886 8749 10956 10331 10623 95805 439 32314 26750 1060 24704 8404 511 3152 451 56529 53981 4520 16114 31101 9436 33424 6173 18...
result:
ok good job, 32676 instruction(s)
Test #13:
score: 0
Accepted
time: 67ms
memory: 30572kb
input:
100000 100000 86322 4929 83579 61717 81028 93863 63624 56270 52901 75158 54370 34740 58954 62029 97574 74084 32946 39229 4694 95648 22560 76996 79300 91701 99942 32414 68575 29471 58051 52619 69874 19847 12767 11792 74151 54115 25 82313 94428 47942 58029 93563 89788 29043 70700 79708 20195 35110 351...
output:
28736 36284 64242 47178 52320 44146 75472 89361 32479 70626 60967 34446 94626 94502 56235 84263 84464 72850 85457 43798 30796 22281 17488 78643 57604 8219 36683 1225 36601 8516 9128 98179 47630 81524 26033 35334 23938 28627 70654 95211 18639 14948 12396 89977 51245 88443 67806 41236 76085 63669 9119...
result:
ok good job, 200002 instruction(s)
Test #14:
score: 0
Accepted
time: 62ms
memory: 41140kb
input:
100000 100000 25428 37272 69619 7282 64587 18392 24381 57301 54320 20485 17236 59526 30823 38757 55343 17370 37512 58190 86473 19428 30287 35049 10303 29575 44114 62530 62330 49078 82698 70083 71507 48140 11831 88428 3173 16351 15822 7562 77244 22730 38140 96265 78005 44175 20548 8320 39079 10796 83...
output:
33298 65648 42626 74493 33961 16350 45165 9527 20153 94539 20081 78040 98299 60266 57270 93892 30385 92531 63099 20754 81184 10020 83577 22032 45123 47455 85740 65173 2351 53020 83231 13648 40145 26501 82823 86328 78353 11057 59209 16422 29055 89949 87723 59860 96747 920 15807 18042 4847 43804 39745...
result:
ok good job, 200002 instruction(s)
Test #15:
score: 0
Accepted
time: 67ms
memory: 40640kb
input:
100000 100000 10889 73894 28668 13203 98139 70161 1044 5038 47917 31269 58227 54508 26143 15200 46703 96821 51030 9669 98391 36506 27411 30543 5988 84867 58309 98558 67523 58507 71133 50142 56482 50601 97335 29657 81621 28543 38313 68151 46162 31389 30858 76334 48708 20205 6111 47722 52359 39481 645...
output:
98117 70994 34107 92529 87642 9874 37816 75929 61564 74060 75206 53462 98668 78810 83205 68204 57569 2251 56302 85958 47081 15102 83356 68758 19810 633 4444 16492 16368 90671 63130 53432 47780 8320 75109 20815 5006 8127 36007 34089 21225 5592 31891 93615 31507 97195 35996 60433 74898 59989 11921 178...
result:
ok good job, 200002 instruction(s)
Test #16:
score: 0
Accepted
time: 1ms
memory: 3712kb
input:
6 6 0 2 2 3 3 1 1 5 2 4 3 4
output:
No solution
result:
ok no solution
Test #17:
score: 0
Accepted
time: 23ms
memory: 8576kb
input:
50000 100000 26144 7421 22412 44494 29727 15433 49590 24000 44200 24509 37641 22526 23764 19318 8924 18734 26213 42867 11997 29991 21761 5388 45970 13904 20943 43174 16307 22885 26999 22799 41360 41456 25911 8522 35863 33750 46384 21531 21281 8834 15465 49013 1753 4004 27082 15982 19334 27615 33954 ...
output:
No solution
result:
ok no solution
Test #18:
score: 0
Accepted
time: 26ms
memory: 10468kb
input:
90000 100000 64261 74711 3299 89019 86241 18036 20799 48883 20053 72155 61408 44131 2243 74042 76172 5660 71753 15465 14846 30249 87138 73873 60899 62854 68202 28401 25560 33368 34094 75934 26244 45318 56438 50859 17557 74836 27193 84062 80223 8263 19255 46960 89294 7521 63921 852 83066 1187 81691 4...
output:
No solution
result:
ok no solution
Test #19:
score: 0
Accepted
time: 34ms
memory: 10112kb
input:
80000 99999 39119 4959 79093 57828 22618 54434 19532 65500 70312 13855 1851 13852 59001 71101 47059 65915 66225 24764 72168 58158 61158 31691 4393 33815 65233 34904 54222 39966 71200 74623 7657 77656 74506 32078 46352 7090 56533 50975 48596 6918 38663 36592 3485 70779 68511 51111 50834 25116 16186 2...
output:
No solution
result:
ok no solution
Test #20:
score: 0
Accepted
time: 27ms
memory: 11620kb
input:
100000 99999 49345 76110 2798 86271 57038 171 77955 15337 19296 48682 98349 5586 31051 49709 29280 27554 35162 52474 25359 81583 69885 46484 25451 32306 33480 72015 1367 90132 91794 22392 54238 86888 54749 9873 20459 26835 47752 90888 77221 48293 88587 256 24236 58681 4801 8895 29926 32488 47889 255...
output:
No solution
result:
ok no solution
Test #21:
score: 0
Accepted
time: 0ms
memory: 3712kb
input:
6 6 0 1 1 2 2 3 3 4 4 5 0 5
output:
0 1 2 3 4 5 MOVE 1 DONE MOVE 2 MOVE 3 MOVE 4 MOVE 5 MOVE 0 DONE
result:
ok good job, 8 instruction(s)
Test #22:
score: 0
Accepted
time: 40ms
memory: 10216kb
input:
100000 100000 59828 64708 47750 16573 57769 81309 99088 79554 69563 87704 77880 38685 82767 50190 69199 35860 57542 75312 81796 99850 33543 99431 56817 78988 68644 9817 40018 32389 78233 43850 51782 70539 97258 21202 36292 91807 94611 42699 4237 7706 97296 17899 82467 22237 545 76141 75385 23587 129...
output:
No solution
result:
ok no solution
Test #23:
score: 0
Accepted
time: 36ms
memory: 13572kb
input:
50000 100000 14198 3429 21041 27019 19584 19711 39287 34721 15399 34050 11683 31085 13955 46499 25087 11616 19485 946 36235 37467 33136 7703 2361 6714 5763 38639 47041 27135 48735 7749 17747 36327 30830 1522 45507 8282 46226 22455 9592 19737 10008 20723 7119 20392 6430 43960 43822 39822 21097 11434 ...
output:
85024 24515 41236 17263 23153 850 21861 22641 11341 17572 37924 43089 27127 96169 88010 98709 7624 75498 36909 2520 92745 31515 5209 24361 54416 98783 86515 17823 99481 6800 23743 67430 26187 15226 72757 33353 48728 32553 1740 9603 7867 83299 67393 20346 16832 73120 75237 37729 43916 13281 14072 281...
result:
ok good job, 32339 instruction(s)
Test #24:
score: 0
Accepted
time: 36ms
memory: 12008kb
input:
90000 100000 70015 24995 73200 87248 12741 75391 34774 22943 21965 53886 1683 18908 54010 88101 39661 54904 11072 62774 48600 64239 20437 85037 54989 8249 14077 74956 44570 32008 27854 72613 89714 70086 21262 1153 2696 9930 67044 74871 36017 2386 10562 85960 32615 76055 1792 74732 36996 14729 15301 ...
output:
No solution
result:
ok no solution
Test #25:
score: 0
Accepted
time: 24ms
memory: 12744kb
input:
40000 100000 2078 4393 29204 30505 29433 14568 15183 32906 20225 19309 21922 9700 31026 31286 7627 7349 33842 1908 17471 16058 13786 36351 33519 10984 14645 23624 30419 11149 15925 25328 5549 24013 18809 27531 32587 38623 11672 7833 19162 25199 32748 31258 11833 31833 26558 11203 24694 8796 29328 19...
output:
55408 538 12810 8799 12690 57884 53450 21138 68751 6058 28456 36663 71705 6687 59088 14284 50142 4251 19141 26549 56096 10880 2819 5320 3245 26253 4096 12614 27681 11517 72777 3023 27221 4186 11838 27351 33253 7314 11138 2460 10 13069 21078 5462 32215 16196 16072 17650 54395 6171 60559 10190 11392 3...
result:
ok good job, 20162 instruction(s)
Test #26:
score: 0
Accepted
time: 33ms
memory: 14640kb
input:
60000 100000 41782 59837 56864 23608 29860 43226 20509 19621 13947 2214 58705 33 9631 17559 52626 17291 4051 39368 45882 40381 20032 16705 49072 47635 58180 35649 4143 36217 10237 50827 40642 15676 33763 53910 31325 39360 43691 31911 56426 47740 28181 36633 16943 11090 34059 53313 43159 22495 41289 ...
output:
63173 27172 6885 4137 8847 6248 62206 58155 3277 15243 39449 77202 35714 1160 30197 24719 52337 3023 12656 38364 31979 3864 22556 3624 63194 8737 13834 320 94424 30387 37762 31316 34501 22871 19873 50444 54274 17835 14911 4065 23789 2560 19453 3289 16839 17481 10589 29362 54163 3718 38862 54829 5307...
result:
ok good job, 30479 instruction(s)