QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#837865 | #9903. 最短路径 | WTR2007 | 0 | 284ms | 30540kb | C++20 | 2.2kb | 2024-12-30 15:23:37 | 2024-12-30 15:23:41 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define MULT_TEST 0
using namespace std;
typedef long double ldb;
typedef unsigned long long ull;
const int INF = 0x3f3f3f3f;
const int MOD = 998244353;
const int N = 302, M = 500005;
int n, f[10][N][N], ans[M];
vector<array<int, 3>> Q[N];
inline int read() {
int w = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
w = (w << 1) + (w << 3) + ch - 48;
ch = getchar();
}
return w * f;
}
inline void DFS(int dep, int l, int r) {
if (l == r) {
for (auto [s, t, id] : Q[l]) ans[id] = f[dep][s][t];
return ;
}
int mid = (l + r) >> 1;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
f[dep + 1][i][j] = f[dep][i][j];
for (int k = mid + 1; k <= r; k++)
for (int i = 1; i <= n; i++) {
if (i == k) continue;
for (int j = 1; j <= n; j++) {
if (i == j || j == k) continue;
f[dep + 1][i][j] = min(f[dep][i][k] + f[dep][k][j], f[dep + 1][i][j]);
}
}
DFS(dep + 1, l, mid);
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
f[dep + 1][i][j] = f[dep][i][j];
for (int k = l; k <= mid; k++)
for (int i = 1; i <= n; i++) {
if (i == k) continue;
for (int j = 1; j <= n; j++) {
if (i == j || j == k) continue;
f[dep + 1][i][j] = min(f[dep][i][k] + f[dep][k][j], f[dep + 1][i][j]);
}
}
DFS(dep + 1, mid + 1, r);
}
inline void Solve() {
int q;
n = read(), q = read();
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
f[0][i][j] = read();
for (int i = 1; i <= q; i++) {
int s = read(), t = read(), p = read();
Q[p].push_back({s, t, i});
}
DFS(0, 1, n);
for (int i = 1; i <= q; i++) printf("%lld\n", ans[i]);
}
signed main() {
int _ = 1;
#if MULT_TEST
_ = read();
#endif
while (_--) Solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Pretests
Final Tests
Test #1:
score: 0
Wrong Answer
time: 6ms
memory: 9920kb
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:
160541512 15701191 21654983 6057504 5327833 13661958 46686875 18735604 26560822 40144352 7711817 18975002 1291868 6259840 78163313 7237520 62201299 42512395 15999394 6922998 16463267 3855425 1292996 3386461 51025610 46038756 11988315 25226595 56646822 39824013 99476988 23733562 5182556 67200889 2447...
result:
wrong answer 1st numbers differ - expected: '65676043', found: '160541512'
Test #2:
score: 0
Wrong Answer
time: 4ms
memory: 9916kb
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:
13978568 9372850 5606111 55661739 26345869 9070391 49127374 65472782 58467314 27079440 50477581 846978 8526620 24496466 12527702 16402483 61417516 3212619 43746134 37281388 7639634 9437130 629338 9817940 9818793 3038580 34281921 55055813 28551934 9284090 147573496 28363700 10789308 1816264 7258755 5...
result:
wrong answer 1st numbers differ - expected: '270396', found: '13978568'
Test #3:
score: 0
Wrong Answer
time: 6ms
memory: 11972kb
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:
8200163 12963885 3966418 28934069 5239721 3766339 5071417 21814562 10934241 6971323 2253867 16045155 10668371 13684723 75411041 9042704 6924946 96369937 91338615 12436104 24777444 9009347 2351686 28437589 13127871 10832862 3427485 5373982 7646151 25487744 37599000 7069878 1603846 76705125 8074174 10...
result:
wrong answer 1st numbers differ - expected: '2561993', found: '8200163'
Test #4:
score: 0
Wrong Answer
time: 219ms
memory: 11308kb
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:
966474 1123507 1291057 1224291 4731435 1865330 1162269 66529 1912196 2076903 1822862 4113243 981900 68728 3780413 1678169 2818450 439183 6567760 6386600 1752577 5340575 722284 703616 414576 2983732 511385 1079905 2933193 7581123 1407997 4671226 1008322 2669454 1904691 7485911 2254267 6966334 2671757...
result:
wrong answer 1st numbers differ - expected: '164487', found: '966474'
Test #5:
score: 0
Wrong Answer
time: 219ms
memory: 11164kb
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:
603283 1269047 8310725 1242904 597814 916966 460194 16530810 1765383 2466527 3642094 1215778 241817 3172128 1846905 1617993 958041 740890 470195 3699865 439280 316520 1626339 1941203 2272775 1389342 2454984 838027 1941274 9500555 1546668 907655 4481740 811423 917936 1169873 1258841 1383728 577599 54...
result:
wrong answer 1st numbers differ - expected: '172637', found: '603283'
Test #6:
score: 0
Wrong Answer
time: 279ms
memory: 30540kb
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:
3035727 1173475 1858814 270869 687742 3546110 686942 147959 1361081 1650731 316811 1064249 3349375 765853 2329243 1472267 957659 2640745 1278428 2034762 350524 2826547 271090 198885 334823 680393 4758735 2332231 447314 1819300 473606 218419 696694 1559736 2645741 1244170 6158886 238437 77991 1446337...
result:
wrong answer 1st numbers differ - expected: '994739', found: '3035727'
Test #7:
score: 0
Wrong Answer
time: 278ms
memory: 29960kb
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:
461065 1546071 812299 4587627 2859380 471233 225623 773927 1557713 2455330 1241152 1240673 1055540 618814 834072 878965 1971463 136221 1831110 2552174 2407329 4947270 1235208 819755 1061876 5237495 1196321 172957 767665 1180167 777425 884802 4364276 968804 755245 852633 2570947 2433421 3252817 55152...
result:
wrong answer 1st numbers differ - expected: '52439', found: '461065'
Test #8:
score: 0
Wrong Answer
time: 272ms
memory: 30084kb
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:
676426 2602624 2140565 1128853 2355003 1784024 1442696 677115 1275911 1331962 3314129 4050986 3230982 1074929 1984598 2040582 3286923 1644956 1180642 2378354 565438 3802753 786625 1426157 1715074 726685 1470485 1963448 843403 965147 5739484 1681498 241498 938685 1031207 3283082 1571693 316610 123883...
result:
wrong answer 1st numbers differ - expected: '54159', found: '676426'
Test #9:
score: 0
Wrong Answer
time: 279ms
memory: 29340kb
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:
716459 2507603 1093614 2583917 301730 1220315 1160393 707287 412659 427491 1560932 1476573 2031635 223356 867905 1243255 3179847 554530 2026817 994028 3919680 433133 382631 4923321 1061795 1818288 71286 574241 2877486 2352808 2856099 7736844 1447740 2756936 536834 7095562 339025 1891817 1454119 1144...
result:
wrong answer 1st numbers differ - expected: '177525', found: '716459'
Test #10:
score: 0
Wrong Answer
time: 284ms
memory: 29624kb
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:
230630 11975669 2144552 3168317 152990 876244 1166230 3567882 7480736 676899 3162493 1219842 2890213 1895592 1426883 1254515 2694494 3397190 2725043 733273 8472730 2224594 129685 577651 543400 2289178 463957 455834 1647459 1963149 7329989 1933625 1520538 785224 2739752 1491588 1259277 2418787 238174...
result:
wrong answer 1st numbers differ - expected: '113041', found: '230630'