QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#841221 | #9903. 最短路径 | dbGIs# | 0 | 131ms | 6608kb | C++14 | 1.7kb | 2025-01-03 15:28:37 | 2025-01-03 15:28:37 |
Judging History
answer
#pragma GCC optimize("Ofast,no-stack-protector")
#include<bits/stdc++.h>
using namespace std;
typedef long long loli;
typedef pair<int, int> pii;
typedef pair<loli, loli> pll;
#define F first
#define S second
const int N=305;
const loli LINF=5e18+7;
loli a[N][N];
pll dp1[N][N];
loli dp2[N][N];
void _solve(){
int n, q;
cin >> n >> q;
for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) cin >> a[i][j];
for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) dp1[i][j]={a[i][j], 1};
for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) dp2[i][j]=LINF;
for(int i=1;i<=n;i++) dp1[i][i]={0, 1};
for(int k=1;k<=n;k++){
for(int i=1;i<=n;i++) if (i!=k){
for(int j=1;j<=n;j++) if (j!=i&&j!=k){
if (dp1[i][j].F>dp1[i][k].F+dp1[k][j].F){
dp2[i][j]=dp1[i][j].F;
dp1[i][j]={dp1[i][k].F+dp1[k][j].F, dp1[i][k].S*dp1[k][j].S};
dp2[i][j]=min({dp2[i][j], dp1[i][k].F+dp2[k][j], dp2[i][k]+dp1[k][j].F});
}else if (dp1[i][j].F==dp1[i][k].F+dp1[j][k].F){
dp1[i][j].S+=dp1[i][k].S*dp1[k][j].S;
dp2[i][j]=min({dp2[i][j], dp1[i][k].F+dp2[k][j], dp2[i][k]+dp1[k][j].F});
}else{
dp2[i][j]=min(dp2[i][j], dp1[i][k].F+dp1[k][j].F);
}
}
}
}
while(q--){
int s, t, p;
cin >> s >> t >> p;
if ((dp1[s][t].F==dp1[s][p].F+dp1[p][t].F)&&(dp1[s][t].S==dp1[s][p].S*dp1[p][t].S)){
cout << dp2[s][t] << '\n';
}else{
cout << dp1[s][t].F << '\n';
}
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int _t=1;
//cin >> _t;
while(_t--) _solve();
}
詳細信息
Pretests
Final Tests
Test #1:
score: 0
Wrong Answer
time: 4ms
memory: 4612kb
input:
100 100 0 7772271323914 22125803016911 3221373 4166251171807 748339783252 34065805188167 50811428832368 1367651438428 24197139580618 6663135541534 27879426632102 15365243414328 10780564011323 2018609024 397712557916 28396067120913 356407886112 44232262619414 162855983068 447276 67425790697675 173378...
output:
64479190 66418 362303 1472816 60315 1458368 118633 51254 433840 72190 49242 130621 44606 443840 421015 383758 1564366 58772 815123 48796 72116 48292 45734 118533 60396 53669 1454333 51254 46954 1534011 56232 73087 40059 423154 414414 25582 71472 57128 51518 64484063 129792 381147 1452294 55068 14598...
result:
wrong answer 1st numbers differ - expected: '65676043', found: '64479190'
Test #2:
score: 0
Wrong Answer
time: 4ms
memory: 4604kb
input:
100 100 0 17578387256913 79089544497 431 594034211131 5170073338267 19361776466479 4427688105 11926603171157 45072603252 11943768005878 50148978000869 106737346550 27519538966959 37137900185801 3989886236022 15439195175968 19533214331980 4915912422439 66000188414990 29166748845681 354388844 66952055...
output:
265283 65581 67162 107726 67266 68363 277026 41789 248733 261241 57694 846978 33496 203518 2180829 260164 977320 863001 270099 15626518 888813 1458051 303768 44048 44901 75480 297022 67903 51619 6752799 45730 82847 297847 51958 295705 107295 879427 15763641 15858555 104072 298950 72533 113744 73169 ...
result:
wrong answer 1st numbers differ - expected: '270396', found: '265283'
Test #3:
score: 0
Wrong Answer
time: 4ms
memory: 5872kb
input:
100 100 0 773801766444 3840925618 1343152952632 64307613436502 8683601469 45434524869106 81117353046 1987337565207 2858076509641 243425132692 1802644161264 25822170325295 6528483907 41283282749 3826491866697 22344866920790 96931641334570 5174664972951 1538931163479 47147864358837 51639382527727 9867...
output:
1998428 829817 686787 1156053 1145991 966291 1295929 874504 2004326 2550089 397933 574030 478031 545098 58077849 1616486 1601337 2271424 91338615 1924533 1998096 884057 679670 1601337 556207 2663959 553878 729277 175115 109362 688349 616951 1258096 1019377 563370 226956 590236 687921 1902752 5265687...
result:
wrong answer 1st numbers differ - expected: '2561993', found: '1998428'
Test #4:
score: 0
Wrong Answer
time: 56ms
memory: 6540kb
input:
300 1000 0 1395254281321 81149967048674 808789341190 79819267873907 57367221292974 13013648824390 64258407230458 14605579839044 12975220495832 120220182607 39743014887008 3266138366431 119198662688 28545770063374 17260222479825 21107475181134 55682577272703 13633518098188 40028750178497 550275401200...
output:
159295 42183 33848 35469 1398593 38800 127953 38642 28153 70255 207718 113053 21116 45195 41673 60152 121072 75263 46173 51801 78557 124177 30448 59954 30412 552017 73880 51539 137671 46116 77036 40114 73689 120803 159295 55155 321614 41817 116865 152177 27523 51070 49754 60852 13097 61192 127498 21...
result:
wrong answer 1st numbers differ - expected: '164487', found: '159295'
Test #5:
score: 0
Wrong Answer
time: 59ms
memory: 6452kb
input:
300 1000 0 6409029058 18566975677517 1453118645319 19988064330 32639805173638 1639371569240 698806223545 185977936143 1082787768141 2239906104533 4403543180683 961039210337 4145037246 1858235 2692041139214 2307668378 1339668614 6253996882 17345652389482 1009665462517 17453151773298 3394297603587 135...
output:
128107 121281 50492 30994 106657 355322 328815 176889 107944 81295 84345 71328 79084 106938 55421 59810 94082 86157 138844 67282 72523 161339 154808 147341 95058 70285 111583 100496 1391006 54325 55980 133866 92449 65644 104119 130119 144216 128674 70972 91643 79010 106470 46683 145797 335639 96138 ...
result:
wrong answer 1st numbers differ - expected: '172637', found: '128107'
Test #6:
score: 0
Wrong Answer
time: 130ms
memory: 6456kb
input:
300 500000 0 87730664049 1603788381608 71952849510530 1142923985 24159738602021 92997246299231 64880292979225 50411033738604 54528465801 31135537246199 231468171471 419 236677264159 38114009155579 2508003778771 57570811058461 24329307886989 292160437 4902439019817 15740104936818 44927292337698 79204...
output:
35313 41019 33982 132758 48351 45950 29590 39020 26386 45343 38987 68043 56094 111935 61577 48338 53405 50382 39127 35997 73897 53895 34130 44871 113426 74257 31331 36682 48589 18152 379855 26260 57011 24486 51228 37369 55051 39901 35605 37584 50107 20019 22262 28825 82267 67496 57415 94923 34854 54...
result:
wrong answer 1st numbers differ - expected: '994739', found: '35313'
Test #7:
score: 0
Wrong Answer
time: 128ms
memory: 6608kb
input:
300 500000 0 52626347413773 1707334632128 70009373655708 25860849031824 32110463708287 3869001849431 346520043666 34919901831451 18512922395 14200680384312 436214584213 79240628473151 14981957306825 1273864589622 475718847939 5308515658147 30868844002 272698735884 23608283030932 509189357147 1289077...
output:
43974 27329 62795 39978 115097 64214 54794 20520 36967 38519 31826 52273 37427 25518 578481 59296 32639 38925 36501 28855 42894 26171 70059 96193 40607 48718 67048 63578 17894 47034 72191 37571 48327 31769 41401 28027 38702 111752 37300 33994 39859 37585 113518 59342 29214 200376 33488 70362 92751 2...
result:
wrong answer 1st numbers differ - expected: '52439', found: '43974'
Test #8:
score: 0
Wrong Answer
time: 125ms
memory: 6548kb
input:
300 500000 0 6330470680301 23874488164149 98626 4160170543478 91396404907 58736315444 12401313360570 14412917281027 38099628392841 282475659499 671873736937 772895099008 19153316198 7022869 27995285198114 11692649915256 7588637657572 823853943323 2206830727999 2151020585 915266887628 5916118204273 1...
output:
54159 241421 49857 31891 50060 29097 91432 245670 102254 63263 32081 2724822 60136 41368 65080 29482 49724 89074 67884 1600112 177704 2748617 206436 45934 134982 237282 781759 49369 40367 59953 228134 34322 21249 180036 23094 2491101 35595 83125 44821 220714 70588 31621 127607 51789 28529 34934 1382...
result:
wrong answer 2nd numbers differ - expected: '293560', found: '241421'
Test #9:
score: 0
Wrong Answer
time: 128ms
memory: 6544kb
input:
300 500000 0 54720923847450 10903523785666 4358689132 83283776625462 8218771493732 35488829878660 3339439 6500864120913 61307902687569 53710291769435 19917041512 463251296446 6646718981507 2456241779832 481716427467 7469732375 21084043486 206425878 740838785326 11139961838828 136091417 806439547295 ...
output:
38408 34283 237199 42703 35487 24818 36795 45221 100995 51020 26354 20195 74786 37048 88229 173568 181158 67353 114676 38718 38179 94140 81631 80175 477729 138464 27075 36270 47593 78993 41379 97035 37469 32662 49556 41241 62244 34148 127347 28221 25692 98623 87654 74269 122955 78024 41452 82134 345...
result:
wrong answer 1st numbers differ - expected: '177525', found: '38408'
Test #10:
score: 0
Wrong Answer
time: 131ms
memory: 6472kb
input:
300 500000 0 5722301682716 8452307607009 329027699594 1815251343 30089254283 943061127487 44841695197962 5020142381745 3623788938103 10069313592506 5560807810421 67387215059128 1502958639680 4306022199080 36093310364434 21620815132153 1864471728058 3394408494751 1018569343784 2241919490 118027786703...
output:
61764 42972 34819 432329 83711 129493 634925 3522534 86849 116428 63284 177184 109361 476463 305542 227657 63508 2622349 392133 42381 41512 51948 129685 59258 112759 81699 53646 452864 103270 368875 4666889 78210 89832 540453 67621 53420 61987 36113 109806 490035 102461 3518244 145692 47135 42728 10...
result:
wrong answer 1st numbers differ - expected: '113041', found: '61764'