QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#849891 | #9903. 最短路径 | pbdqz1 | 0 | 378ms | 23680kb | C++14 | 1.3kb | 2025-01-09 19:01:49 | 2025-01-09 19:01:55 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=311;
int n,q;
long long f[11][N][N];
vector<tuple<int,int,int> >qr[N];
long long ans[511111];
void solve(int l,int r,int d=0)
{
if(l==r)
{
for(auto [x,y,id]:qr[l])
ans[id]=f[d][x][y];
return;
}
int m=(l+r)>>1;
for(int k=m+1;k<=r;k++)
{
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
f[d+1][i][j]=f[d][i][j];
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
f[d+1][i][j]=min(f[d+1][i][j],f[d][i][k]+f[d][k][j]);
}
solve(l,m,d+1);
for(int k=l;k<=m;k++)
{
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
f[d+1][i][j]=f[d][i][j];
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
f[d+1][i][j]=min(f[d][i][j],f[d][i][k]+f[d][k][j]);
}
solve(m+1,r,d+1);
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin>>n>>q;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
cin>>f[0][i][j];
for(int i=1;i<=q;i++)
{
int x,y,p;
cin>>x>>y>>p;
qr[p].push_back({x,y,i});
}
solve(1,n);
for(int i=1;i<=q;i++)
cout<<ans[i]<<"\n";
}
Details
Tip: Click on the bar to expand more detailed information
Pretests
Final Tests
Test #1:
score: 0
Wrong Answer
time: 11ms
memory: 11784kb
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:
326856243511 607683607310 591719235857 25646953618 36506853840 1273344768825 119331118198 30603126855 58255338346 8810524672 250647555055 74667479753 2802560462705 7411396867 6120644936 127187255739 322442942347 3840472348 3809529207 80834918035 27492618028 20649144546 2812758521391 3550469536 42686...
result:
wrong answer 1st numbers differ - expected: '65676043', found: '326856243511'
Test #2:
score: 0
Wrong Answer
time: 11ms
memory: 11764kb
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:
9185749551 305357910319 189938903340 324609341316 243167152674 69481418061 19852129270 385459959154 58028669090 83121191656 138437912317 2299180868 38777389707 56427583386 4898573288 1407126308268 68432300954 237996181507 19451023581 214385240457 39492241225 1151093445 629338 8723282618 6760976305 4...
result:
wrong answer 1st numbers differ - expected: '270396', found: '9185749551'
Test #3:
score: 0
Wrong Answer
time: 10ms
memory: 11820kb
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:
20634843624 4714110015 108180803853 14173270327 232590072264 4322445643 19691774683 8227249779 81914851734 94432764811 252979179465 31388218685 130898031964 7285861806 298894742492 43637981071 140216751247 4659812513 496981219 54316814071 4198836660 131707824083 11408815636 425607710215 18717596757 ...
result:
wrong answer 1st numbers differ - expected: '2561993', found: '20634843624'
Test #4:
score: 0
Wrong Answer
time: 293ms
memory: 12132kb
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:
7108357989 48823646515 28852507304 4556457054 2170551075 66234480768 110725177074 3126843977 442557320709 12730856119 32554947565 543533164 43679780407 137604742552 39476534824 1389512330 12198715480 19505688034 80065431341 74680594363 53028031831 30782689225 19841238024 10384896404 8216280624 25371...
result:
wrong answer 1st numbers differ - expected: '164487', found: '7108357989'
Test #5:
score: 0
Wrong Answer
time: 286ms
memory: 11852kb
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:
144920139905 32851001984 52728878 35390247650 72435917453 145652225028 884738133499 1222462348 28441212106 40711175371 25632427430 490650492095 752790837 178825286072 32798836416 563877681710 58167184273 319835171676 161635632367 15991989334 2406146238 5892878751 223419885016 28237792156 49703783230...
result:
wrong answer 1st numbers differ - expected: '172637', found: '144920139905'
Test #6:
score: 0
Wrong Answer
time: 362ms
memory: 23680kb
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:
6881623243 30588912 476653252 57491243230 60472456605 4474621852 6798180319 158244283247 11500150081 211258351715 526173 221195086013 2217086940 18099204786 174309018742 1819523468 2617770611 26019734485 7717769800 41705320990 1295770102 9636238829 1390503 6148470473 33267039262 28511215044 92958156...
result:
wrong answer 1st numbers differ - expected: '994739', found: '6881623243'
Test #7:
score: 0
Wrong Answer
time: 378ms
memory: 23092kb
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:
37698569 43549674 155925524 139232001370 65593818884 11084394408 20667360889 31502074 384930152869 11613284807 571691969757 11714454658 14243267581 22423248440 46022729685 2322995039663 15465342955 83591975746 24273388665 174599137801 16666504734 33666338185 11049695702 129557571820 75421220945 4300...
result:
wrong answer 1st numbers differ - expected: '52439', found: '37698569'
Test #8:
score: 0
Wrong Answer
time: 370ms
memory: 22524kb
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:
14503656578 19858992 1065628578 50936066053 41836251589 118049963220 26257262775 42600878 616807037 192215677621 24208957537 2821800913 57692644 1090978849971 35954384599 9409685436 64159675855 2306787486 3391312931 21390652757 86886773875 51641135987 42701351567 2541156123 5022941773 673318503271 2...
result:
wrong answer 1st numbers differ - expected: '54159', found: '14503656578'
Test #9:
score: 0
Wrong Answer
time: 377ms
memory: 22940kb
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:
2057188135 78472039082 51653186842 58652743464 16860612775 18778489838 19043657113 24879419834 102461550875 662520541447 10865852008 12441586233 8655173272 78718399711 1882979100 37018467913 55971965187 116693637154 34958329094 15393199130 8162422309 45721151858 792955330 36302613965 10244042586 289...
result:
wrong answer 1st numbers differ - expected: '177525', found: '2057188135'
Test #10:
score: 0
Wrong Answer
time: 377ms
memory: 23392kb
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:
156260265 27867694694 192454582740 117599053385 57225601591 532987623 16535580300 204700140192 92083860972 61482234206 66470523801 3500031320 30912896351 4436512221 27376601007 26187945222 499314449899 2080178261 5828949410 7941387261 3662680143 127537224 129685 130279242744 1113448524 354165739285 ...
result:
wrong answer 1st numbers differ - expected: '113041', found: '156260265'