QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#849888 | #9903. 最短路径 | pbdqz1 | 0 | 373ms | 21848kb | C++14 | 1.3kb | 2025-01-09 19:01:21 | 2025-01-09 19:01:21 |
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];
int 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: 7ms
memory: 11836kb
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:
438729015 2093218574 -986250991 -122850158 2147115472 2034449209 -927966090 538355783 -1874203798 220590080 1539451887 1653035721 -2053181583 -1178537725 1825677640 -1661763141 320395147 -454494948 -485438089 -769460589 1722814252 -825691934 -445057489 -744497760 1663104416 -580349715 929389504 2016...
result:
wrong answer 1st numbers differ - expected: '65676043', found: '438729015'
Test #2:
score: 0
Wrong Answer
time: 10ms
memory: 11856kb
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:
595814959 415232303 960342316 -1808173180 -1645983198 761941325 -1622707210 -1087097486 -2100873054 1516813032 998958845 -1995786428 122684043 593008538 603605992 -1622964820 -287175782 1772980227 -2023812899 -363124343 837535561 1151093445 629338 133348026 -1828958287 -571715032 -1231795448 -296929...
result:
wrong answer 1st numbers differ - expected: '270396', found: '595814959'
Test #3:
score: 0
Wrong Answer
time: 10ms
memory: 11780kb
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:
-839992856 419142719 806621453 1288368439 661838280 27478347 -1783061797 -362684813 310473110 -56515701 -423890999 1323447613 2049013084 -1304072786 -1752968228 688308111 -1517169521 364845217 496981219 -1517760777 -96130636 -1436162093 -1476086252 405947911 1537727573 -265548192 -661353155 14533096...
result:
wrong answer 1st numbers differ - expected: '2561993', found: '-839992856'
Test #4:
score: 0
Wrong Answer
time: 276ms
memory: 12548kb
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:
-1481576603 1579006259 -1212263768 261489758 -2124416221 1809971328 -943972622 -1168123319 175689221 -154045769 -1804790803 543533164 730107447 165789080 821829160 1389512330 -686186408 -1969148446 -1538947283 1666150331 1488424279 717918153 -1633598456 1794961812 -373653968 314863879 -875022707 -10...
result:
wrong answer 1st numbers differ - expected: '164487', found: '-1481576603'
Test #5:
score: 0
Wrong Answer
time: 277ms
memory: 12220kb
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:
-1108748159 -1508736384 52728878 1030509282 -578526579 -376663036 -25129477 1222462348 -1623558966 2056469707 -137376346 1024220351 752790837 -1563340360 -1560901952 1236965934 -1962357871 2007591772 -1573124881 -1187879850 -1888821058 1597911455 81585624 -1826978916 -1178374033 691016068 -189353976...
result:
wrong answer 1st numbers differ - expected: '172637', found: '-1108748159'
Test #6:
score: 0
Wrong Answer
time: 372ms
memory: 21848kb
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:
-1708311349 30588912 476653252 1656668382 342914461 179654556 -1791754273 -669506705 -1384751807 804954211 526173 -2143213379 -2077880356 919335602 -1784640394 1819523468 -1677196685 249930709 -872164792 -1244351970 1295770102 1046304237 1390503 1853503177 -1092699106 -1553556028 705881037 -51273429...
result:
wrong answer 1st numbers differ - expected: '994739', found: '-1708311349'
Test #7:
score: 0
Wrong Answer
time: 372ms
memory: 21172kb
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 1793047898 1169309444 -1800507480 -807475591 31502074 -1616903771 -1271617081 461319389 -1170447230 1358365693 948411960 -1221910571 -582267473 -1714526229 1987597122 -1496415111 -1494521335 -513364450 -693400183 -1835206186 708552940 -1888190383 5601540 880790213 -208662...
result:
wrong answer 1st numbers differ - expected: '52439', found: '37698569'
Test #8:
score: 0
Wrong Answer
time: 372ms
memory: 20712kb
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:
1618754690 19858992 1065628578 -603541499 -1113421371 2085846228 487458999 42600878 616807037 -1057850699 -1560846239 -1473166383 57692644 57156787 1594646231 819750844 -264833585 -1988179810 -903654365 -84183723 987427955 101528435 -248321393 -1753811173 727974477 -991362201 202073220 185626081 -89...
result:
wrong answer 1st numbers differ - expected: '54159', found: '1618754690'
Test #9:
score: 0
Wrong Answer
time: 373ms
memory: 20604kb
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 1162627754 113579290 -1476798680 -319256409 1598620654 1863787929 -890383942 -617664229 1095577863 -2019049880 -443315655 65238680 1408988383 1882979100 -1636237751 137390339 729520162 598590726 -1786670054 -427512283 -1523488398 792955330 1942875597 1654107994 -1395735849 1583782686 1804...
result:
wrong answer 1st numbers differ - expected: '177525', found: '2057188135'
Test #10:
score: 0
Wrong Answer
time: 363ms
memory: 20644kb
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 2097890918 -818945580 1634936393 1391026743 532987623 -644288884 -1458290016 1889547756 1352692062 2046014361 -794935976 848125279 141544925 1606797231 418141446 1098243563 2080178261 1533982114 -648547331 -632287153 127537224 129685 1430223864 1113448524 1978421013 936778436 -138471670 -1...
result:
wrong answer 1st numbers differ - expected: '113041', found: '156260265'