QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#431285 | #4197. Natural Navigation | kevinyang# | AC ✓ | 427ms | 117228kb | C++14 | 1.3kb | 2024-06-05 10:01:31 | 2024-06-05 10:01:31 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
signed main(){
cin.tie(nullptr)->sync_with_stdio(false);
int n,m,k;
cin >> n >> m >> k;
vector<vector<pair<int,pii>>>adj(n+1); // reverse graph
vector<map<int,int>>hm(n+1);
vector<vector<int>>edges(m);
for(int i = 0; i<m; i++){
int x,y,w;
cin >> x >> y >> w;
int l;
cin >> l;
adj[y].push_back({w,{i,x}});
for(int j = 0; j<l; j++){
int c;
cin >> c;
hm[x][c]++;
edges[i].push_back(c);
}
}
vector<int>dis(n+1,(int)1e18);
vector<bool>vis(n+1);
vector<bool>good(n+1);
priority_queue<pair<int,pii>,vector<pair<int,pii>>,greater<pair<int,pii>>>pq;
dis[n] = 0;
vis[0] = true;
for(auto [w,e]: adj[n]){
int idx = e.first;
int nxt = e.second;
pq.push({w,{idx,nxt}});
}
while(pq.size()){
auto [dist, cur] = pq.top(); pq.pop();
int idx = cur.first;
int dest = cur.second;
if(vis[dest])continue;
for(int c: edges[idx]){
hm[dest][c]--;
if(hm[dest][c] == 0){
vis[dest] = true;
dis[dest] = dist;
}
}
if(vis[dest]){
for(auto [w, e] : adj[dest]){
pq.push({w + dist, e});
}
}
}
if(vis[1]){
cout << dis[1] << '\n';
}
else{
cout << "impossible\n";
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3672kb
input:
4 6 2 1 2 6 1 1 1 3 3 1 2 2 3 5 1 2 2 4 8 1 1 3 1 4 2 1 2 3 4 3 1 1
output:
14
result:
ok single line: '14'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3472kb
input:
3 4 3 1 2 300 2 1 2 2 1 2000 2 3 1 1 3 80 2 2 1 2 2 42 1 2
output:
impossible
result:
ok single line: 'impossible'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3588kb
input:
3 2 3 1 2 1 3 1 2 3 1 3 1 2 1 2
output:
impossible
result:
ok single line: 'impossible'
Test #4:
score: 0
Accepted
time: 1ms
memory: 3644kb
input:
4 5 1 1 4 1 1 1 4 3 1 1 1 3 2 1 1 1 2 1 1 1 1 1 3 1 1 1
output:
impossible
result:
ok single line: 'impossible'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3636kb
input:
2 2 3 1 2 3 3 1 2 3 1 2 4 3 1 2 3
output:
4
result:
ok single line: '4'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3576kb
input:
10 12 3 4 4 5 1 1 1 7 5 1 1 1 2 5 1 1 8 4 2 1 1 8 10 5 1 1 6 8 2 1 2 6 5 1 1 2 6 10 7 1 3 5 5 8 1 2 7 1 5 1 1 2 1 6 1 1 2 8 1 1 1
output:
impossible
result:
ok single line: 'impossible'
Test #7:
score: 0
Accepted
time: 1ms
memory: 3648kb
input:
10 19 3 2 2 5 1 2 2 9 4 1 1 2 10 7 1 3 2 4 4 1 3 3 1 9 1 3 5 3 3 1 1 9 3 5 1 2 9 5 10 1 1 9 9 8 1 1 9 6 3 1 3 8 3 6 2 1 3 10 8 8 1 3 10 1 4 1 1 1 9 5 1 1 4 2 2 1 3 4 3 3 1 1 6 9 4 1 2 6 8 4 1 2 6 4 8 1 3
output:
impossible
result:
ok single line: 'impossible'
Test #8:
score: 0
Accepted
time: 0ms
memory: 3676kb
input:
10 40 3 4 4 3 2 2 3 4 6 1 1 3 4 10 4 1 2 4 2 4 1 2 4 7 5 2 1 3 6 8 2 2 1 2 6 10 7 1 3 6 2 5 2 2 3 8 10 7 1 3 8 1 10 1 2 9 8 1 1 1 9 10 7 1 1 9 2 10 2 2 3 9 5 9 1 1 10 4 1 1 3 10 6 5 1 1 10 9 10 1 1 10 2 5 1 2 10 1 4 1 2 10 7 9 1 1 2 6 6 1 2 2 8 3 1 3 2 9 8 1 2 2 2 4 2 1 2 2 5 8 1 2 2 7 3 1 1 5 2 1 1...
output:
39
result:
ok single line: '39'
Test #9:
score: 0
Accepted
time: 331ms
memory: 91844kb
input:
10000 498740 1000 7756 7812 146482 1 738 7756 4571 581789 1 497 7756 1367 703256 1 674 7756 8199 491446 1 238 7756 6114 941752 1 26 7756 8739 775363 1 30 7756 2619 313750 1 327 7756 7187 113027 1 268 7756 6943 91064 1 366 7756 4027 565567 1 863 7756 5210 613674 1 45 7756 2625 693644 1 468 7756 5013 ...
output:
172783
result:
ok single line: '172783'
Test #10:
score: 0
Accepted
time: 253ms
memory: 75664kb
input:
1000 393460 1000 423 423 637689 1 427 423 726 460151 1 920 423 311 685370 1 597 423 412 701330 1 553 423 330 717005 1 862 423 676 524095 2 366 411 423 216 69984 1 299 423 272 363386 1 763 423 652 926886 1 928 423 357 607150 1 347 423 927 534335 1 315 423 545 655568 2 267 828 423 842 602690 1 865 423...
output:
33452
result:
ok single line: '33452'
Test #11:
score: 0
Accepted
time: 153ms
memory: 44160kb
input:
2000 484362 2 1289 135 761615 1 2 1289 1163 944919 1 2 1289 507 138396 1 2 1289 1879 154507 1 2 1289 1934 484632 1 2 1289 1049 913244 1 2 1289 626 900547 1 1 1289 1183 718783 1 1 1289 648 250102 1 2 1289 64 202751 1 2 1289 364 916080 1 1 1289 1970 703438 1 2 1289 382 559816 1 1 1289 1232 544698 1 2 ...
output:
impossible
result:
ok single line: 'impossible'
Test #12:
score: 0
Accepted
time: 125ms
memory: 38900kb
input:
1000 421412 3 296 81 449614 1 3 296 636 731202 1 3 296 149 645560 1 2 296 560 570799 1 2 296 92 483079 1 3 296 83 65086 1 2 296 239 502528 1 3 296 692 952771 1 1 296 387 27706 1 3 296 489 203962 1 1 296 583 276352 1 3 296 968 443564 2 1 3 296 68 859602 1 2 296 432 245638 1 2 296 294 933292 1 3 296 2...
output:
impossible
result:
ok single line: 'impossible'
Test #13:
score: 0
Accepted
time: 109ms
memory: 38160kb
input:
1000 413799 4 570 396 203345 1 3 570 801 3447 2 2 4 570 393 825231 1 2 570 161 433365 1 4 570 44 855873 1 1 570 127 873092 1 1 570 781 749825 1 3 570 897 334612 1 1 570 953 166340 1 3 570 922 865765 3 1 2 3 570 259 949726 1 2 570 932 770327 1 1 570 640 140986 2 1 4 570 871 92089 1 2 570 326 262958 1...
output:
impossible
result:
ok single line: 'impossible'
Test #14:
score: 0
Accepted
time: 243ms
memory: 39788kb
input:
25000 250000 6 17414 524 2552 2 1 5 6925 13350 4266 2 1 5 21567 1185 10194 2 5 6 6852 11401 5660 2 1 2 4925 10674 1 2 3 6 17895 7429 1 2 4 5 10990 5624 1 2 5 6 17763 9586 4510 2 2 4 3807 23200 1 2 3 6 16899 3423 17559 2 2 3 65 20870 9386 2 1 5 19750 16854 9277 2 2 3 5144 12747 1473 2 2 6 10320 1974 ...
output:
25003
result:
ok single line: '25003'
Test #15:
score: 0
Accepted
time: 230ms
memory: 38860kb
input:
25000 250000 6 9264 24855 1 2 2 5 10001 17614 2782 2 4 5 16769 24107 11599 2 5 6 14392 10268 5803 2 2 4 4593 21267 8734 2 1 4 4656 24084 11510 2 1 5 5357 21697 2724 2 4 5 11922 1206 1525 2 4 5 5664 9582 9415 2 1 6 12899 23693 10228 2 1 5 11271 10752 9059 2 4 5 21469 19200 5355 2 2 5 1939 13213 12197...
output:
25005
result:
ok single line: '25005'
Test #16:
score: 0
Accepted
time: 229ms
memory: 39016kb
input:
25000 250000 6 4151 24847 16676 2 1 3 12906 3823 349 2 2 6 15090 17814 16676 2 1 6 15670 20829 7408 2 4 6 21348 13857 11714 2 4 5 4679 20662 14579 2 2 6 1541 17190 1226 2 4 6 23727 22673 7454 2 2 6 11914 480 11063 2 2 3 13366 13999 3138 2 2 4 18299 668 17996 2 1 3 18541 11685 16126 2 2 5 8748 3304 2...
output:
25004
result:
ok single line: '25004'
Test #17:
score: 0
Accepted
time: 389ms
memory: 116464kb
input:
500000 499999 6 327641 265002 1000000 1 4 335152 364616 1000000 1 6 304056 199957 1000000 1 1 31943 238826 1000000 1 3 467115 226265 1000000 1 1 452304 272411 1000000 1 5 276919 312727 1000000 1 6 35635 101200 1000000 1 5 41182 376552 1000000 1 5 392601 47344 1000000 1 1 74827 378739 1000000 1 6 106...
output:
499999000000
result:
ok single line: '499999000000'
Test #18:
score: 0
Accepted
time: 235ms
memory: 36724kb
input:
25000 250000 6 13556 19067 591829 2 3 5 13774 1699 467303 2 1 6 18569 19613 51894 2 2 6 18343 14076 351259 2 2 3 10229 5323 819364 2 5 6 272 5706 402046 2 1 5 15615 21590 20621 2 1 3 6347 3277 480576 2 2 4 4203 2418 86185 2 4 5 10479 20309 268761 2 2 6 5924 10590 398059 2 3 6 10312 20931 206283 2 1 ...
output:
225325344
result:
ok single line: '225325344'
Test #19:
score: 0
Accepted
time: 256ms
memory: 36696kb
input:
25000 250000 6 17071 15121 372902 2 1 3 19454 14119 396730 2 4 5 7751 13805 168177 2 1 2 24725 16352 676276 2 2 3 23933 13751 232546 2 1 6 12849 12532 464141 2 1 4 13636 17422 220826 2 3 6 10635 21038 219240 2 5 6 8305 8986 956730 2 2 5 223 8232 517076 2 2 5 15528 11798 699196 2 1 6 10409 15785 6823...
output:
224183495
result:
ok single line: '224183495'
Test #20:
score: 0
Accepted
time: 236ms
memory: 36760kb
input:
25000 250000 6 24380 2953 36492 2 1 3 10928 23391 750247 2 2 5 22912 10678 459666 2 1 4 13532 10421 162174 2 1 5 10835 12373 970457 2 1 3 5604 6128 803124 2 2 4 20942 24990 87350 2 2 3 23268 13065 574731 2 4 6 23962 12196 502641 2 3 4 20804 21282 764498 2 4 6 13433 18671 679673 2 3 5 5734 18936 8079...
output:
223635232
result:
ok single line: '223635232'
Test #21:
score: 0
Accepted
time: 276ms
memory: 47556kb
input:
25000 250000 20 15215 9184 424294 2 13 16 8212 14908 454354 2 2 11 4637 10964 478156 2 8 15 1934 16075 246809 2 5 11 2302 23852 510742 2 3 19 6534 23284 731895 2 15 20 8818 14293 384477 2 14 17 10395 22749 690481 2 1 3 3349 3089 616611 2 7 11 12106 12484 720721 2 7 17 12227 20697 868514 2 13 14 9000...
output:
60910058
result:
ok single line: '60910058'
Test #22:
score: 0
Accepted
time: 308ms
memory: 47540kb
input:
25000 250000 20 18936 165 370043 2 10 17 21962 2975 9846 2 15 18 6244 13952 92336 2 13 14 20048 1906 820570 2 6 10 23360 2362 532380 2 15 17 19736 19602 104399 2 14 20 339 2234 212024 2 3 11 20444 24575 666916 2 9 13 14444 3643 813948 2 8 10 22056 24431 173120 2 9 20 12090 23119 964764 2 9 15 15816 ...
output:
57809373
result:
ok single line: '57809373'
Test #23:
score: 0
Accepted
time: 312ms
memory: 47540kb
input:
25000 250000 20 21220 19277 757364 2 7 14 14167 6099 793246 2 1 20 20002 17299 382663 2 14 19 16317 3567 859055 2 16 20 20764 20160 282598 2 2 17 24642 12881 357440 2 15 16 16214 15488 113631 2 8 15 2447 10035 315867 2 8 13 23859 5883 931260 2 11 15 6047 18197 988365 2 14 18 7050 17035 37629 2 1 18 ...
output:
57371862
result:
ok single line: '57371862'
Test #24:
score: 0
Accepted
time: 254ms
memory: 34868kb
input:
2500 250000 37 1491 2244 138338 2 10 24 850 276 730043 2 2 36 1183 1422 989338 2 3 19 763 2426 197779 2 29 34 387 1264 334080 2 4 11 1461 348 946035 2 5 20 1785 1018 791601 2 25 36 1927 1271 893072 2 2 15 395 572 71562 2 8 31 2425 489 269027 2 17 35 968 2375 259660 2 19 22 1506 2260 497131 2 13 18 2...
output:
8850811
result:
ok single line: '8850811'
Test #25:
score: 0
Accepted
time: 196ms
memory: 29480kb
input:
2500 250000 20 864 836 201867 2 4 13 160 2145 748594 2 4 13 919 2158 615380 2 15 16 2310 1248 585173 2 5 16 1664 864 886730 2 14 17 2498 2002 678413 2 14 18 1820 879 159748 2 11 17 727 698 362136 2 10 18 742 2013 191194 2 6 19 668 1564 308421 2 9 18 1182 498 322162 2 14 19 96 115 542126 2 9 14 1695 ...
output:
8854483
result:
ok single line: '8854483'
Test #26:
score: 0
Accepted
time: 62ms
memory: 12692kb
input:
250 25000 75 98 69 902 20 15 20 24 31 34 35 43 44 49 51 53 54 58 59 60 66 69 71 73 74 174 135 16 20 15 17 21 24 31 35 39 40 49 51 57 58 59 60 61 63 65 67 69 70 193 70 755 20 2 13 16 18 25 26 29 31 33 41 44 50 51 52 59 60 65 66 68 70 41 238 478 20 6 15 23 25 26 33 35 39 45 51 52 54 56 58 59 63 65 71 ...
output:
848774
result:
ok single line: '848774'
Test #27:
score: 0
Accepted
time: 294ms
memory: 105380kb
input:
500000 499999 1 129819 334278 213654 1 1 432613 325294 452027 1 1 251183 404282 562419 1 1 27965 213884 636645 1 1 128357 72801 243018 1 1 427255 282766 906551 1 1 427255 140622 656040 1 1 486045 316880 183311 1 1 486045 240287 361017 1 1 186570 425960 402596 1 1 189239 357853 686837 1 1 183121 3535...
output:
impossible
result:
ok single line: 'impossible'
Test #28:
score: 0
Accepted
time: 286ms
memory: 117228kb
input:
500000 499998 1000 252531 487972 750278 1 585 119240 95125 349371 1 751 449874 12062 210177 1 150 186408 416666 897552 1 593 403610 362707 962077 1 483 307745 373408 805711 1 106 408017 396442 265062 1 100 28902 425784 730392 1 739 28902 466744 18632 1 523 396534 266523 330947 1 806 333264 441454 93...
output:
impossible
result:
ok single line: 'impossible'
Test #29:
score: 0
Accepted
time: 289ms
memory: 97980kb
input:
250000 499996 1000 71962 196041 872550 1 435 59790 40667 580161 1 146 59790 171310 787388 1 646 165764 8554 736671 1 98 165764 178892 854036 1 684 86194 163331 556739 1 815 86194 85502 990076 1 62 68894 179020 701410 1 118 68894 248065 698279 1 392 218516 205213 402302 1 650 218516 16805 222260 1 71...
output:
impossible
result:
ok single line: 'impossible'
Test #30:
score: 0
Accepted
time: 420ms
memory: 93168kb
input:
100000 499986 1000 4280 637 479679 1 325 4280 95600 835482 1 861 4280 95289 752295 1 193 4280 52439 690438 1 463 57034 39748 486698 1 503 57034 20717 33777 1 631 57034 20126 363405 1 466 57034 16526 604577 1 375 57034 74957 295029 1 423 57034 86694 618780 1 310 57034 80697 409940 1 950 2734 88550 61...
output:
2289708
result:
ok single line: '2289708'
Test #31:
score: 0
Accepted
time: 427ms
memory: 99664kb
input:
180000 499995 1000 171908 5878 228782 1 235 171908 31043 385652 1 441 171908 34378 768177 1 40 171908 138844 143625 1 613 28493 164333 585273 1 215 28493 52585 139512 1 987 116253 39696 140192 1 291 90717 145775 324611 1 794 90717 152849 458490 1 843 90717 101956 695122 1 601 72657 137609 765923 1 5...
output:
4546929
result:
ok single line: '4546929'
Test #32:
score: 0
Accepted
time: 296ms
memory: 89400kb
input:
250000 499999 3 216829 66353 112821 1 3 209696 6198 600776 1 3 209696 68302 645025 1 1 209696 153333 149789 1 3 106819 63134 844614 1 3 106819 73565 409583 1 2 67517 89908 174654 1 3 67517 134551 286125 1 1 67517 193754 73298 1 3 67517 163497 323753 1 3 67517 31104 91819 1 2 140557 27968 148449 1 1 ...
output:
impossible
result:
ok single line: 'impossible'
Test #33:
score: 0
Accepted
time: 398ms
memory: 87676kb
input:
100000 499990 10 85697 79108 749990 1 10 85697 84577 647194 1 9 85697 30687 140479 1 9 85697 87225 571066 1 8 85697 36925 173081 1 9 85697 26658 556128 1 5 81553 64509 444089 1 7 81553 69789 684864 1 9 81553 10277 534894 1 5 81553 61863 705869 1 10 81553 30497 897790 1 5 81553 38190 935024 1 9 63189...
output:
3410991
result:
ok single line: '3410991'
Test #34:
score: 0
Accepted
time: 406ms
memory: 90076kb
input:
180000 499994 7 153929 142919 283436 1 5 153929 59197 129416 1 6 91768 165518 857968 1 5 16814 141275 194227 1 2 16814 109335 935035 1 5 16814 175299 255411 1 2 108882 42744 277496 1 5 108882 69485 708644 1 5 108882 35641 202855 1 1 108882 105846 205100 1 6 108882 14625 691439 1 1 39733 154187 50133...
output:
8109578
result:
ok single line: '8109578'