QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#839678#9903. 最短路径kenkenken#0 108ms435776kbC++231.7kb2025-01-02 00:42:162025-01-02 00:42:17

Judging History

你现在查看的是最新测评结果

  • [2025-01-02 00:42:17]
  • 评测
  • 测评结果:0
  • 用时:108ms
  • 内存:435776kb
  • [2025-01-02 00:42:16]
  • 提交

answer

#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define pob pop_back
#define all(x) begin(x), end(x)
#define SZ(x) ssize(x)
using namespace std;

#ifdef LOCAL
#define HEHE freopen("in.txt", "r", stdin);
#define debug(HEHE...) cerr << #HEHE << " = ", dout(HEHE)
void dout() { cerr << "\n"; }
template<typename T, typename... U>
void dout(T t, U... u) { cerr << t << ' '; dout(u...); }
#else
#define HEHE ios_base::sync_with_stdio(0), cin.tie(0);
#define debug(...) 7122
#endif

#define FOR(i, a, b) for (int i = (a); i <= (b); i++)

#define chmax(a, b) a = (a) > (b) ? (a) : (b)
#define chmin(a, b) a = (a) < (b) ? (a) : (b)

#define int long long

const int inf = 1ll << 60;
int n, q;
vector<vector<int>> dis, pre[305], suf[305];

signed main() {
    HEHE
    cin >> n >> q;
    dis.assign(n + 1, vector<int>(n + 1));
    pre[0].assign(n + 1, vector<int> (n + 1));
    FOR (i, 1, n) FOR (j, 1, n)
        cin >> dis[i][j];
    pre[0] = suf[n + 1] = dis;
    FOR (k, 1, n) {
        pre[k] = pre[k - 1];
        FOR (i, 1, n) FOR (j, 1, n) {
            chmin(pre[k][i][j], pre[k][i][k] + pre[k][k][j]);
        }
    }
    for (int k = n; k >= 1; k--) {
        suf[k] = suf[k + 1];
        FOR (i, 1, n) FOR (j, 1, n) {
            chmin(suf[k][i][j], suf[k][i][k] + suf[k][k][j]);
        }
    }
    while (q--) {
        int s, t, p; cin >> s >> t >> p;
        int ans = inf;
        chmin(ans, pre[p-1][s][t]);
        chmin(ans, suf[p+1][s][t]);
        FOR (i, 1, n) {
            if (i != p)
                chmin(ans, min(pre[p-1][s][i], suf[p+1][s][i]) + min(pre[p-1][i][t], suf[p+1][i][t]));
        }
        cout << ans << '\n';
    }
}

Details

Tip: Click on the bar to expand more detailed information

Pretests


Final Tests

Test #1:

score: 0
Wrong Answer
time: 8ms
memory: 19936kb

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:

66780767
436874
362303
1486937
300451
2700414
46686875
478846
989861
350083
2989287
377654
4620137
8796690
39032539
3400314
5068225
5821823
1914167
132338
21837696
321631
21822925
446416
40490543
10927715
1454333
3750900
46615196
3138905
1449806
371747
8916113
6186205
2447492
1065302
2009973
5593070...

result:

wrong answer 1st numbers differ - expected: '65676043', found: '66780767'

Test #2:

score: 0
Wrong Answer
time: 4ms
memory: 19988kb

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
2628615
2375637
1176100
8528453
1442740
28215974
1280064
4051627
19602751
695654
846978
33496
1833946
6768853
4160546
4801514
3212619
28243174
50707966
2878248
16468676
322009
6201248
15793308
334809
1472801
272409
17699293
9284090
65108428
6213095
4314169
8536440
2922231
107295
7078105
217...

result:

wrong answer 1st numbers differ - expected: '270396', found: '13978568'

Test #3:

score: 0
Wrong Answer
time: 3ms
memory: 19932kb

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:

2979421
1290297
10074796
1156053
2916029
2512475
15473789
874504
4425070
2550089
842128
2104789
2378804
4727338
58077849
1616486
8304714
87127444
91338615
1929592
2957991
951355
5988889
3642721
1337678
12167200
2986433
4926652
6052434
18005450
1217797
5346985
1603846
5188432
8064408
1744001
1890265
...

result:

wrong answer 1st numbers differ - expected: '2561993', found: '2979421'

Test #4:

score: 0
Wrong Answer
time: 104ms
memory: 435776kb

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:

164487
70070
450995
1204009
1652037
573641
138885
83511
359339
715696
588597
383489
49901
68728
222536
488920
763965
439183
370927
215838
1331776
2089311
833660
336632
363368
736132
1064984
1766862
177933
679980
1349658
185579
285259
500411
373481
2112631
389712
2014250
623553
440113
1494266
811980
...

result:

wrong answer 3rd numbers differ - expected: '33848', found: '450995'

Test #5:

score: 0
Wrong Answer
time: 108ms
memory: 435768kb

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:

406595
832868
196594
51737
227674
689862
339714
15092733
575093
728295
292712
1215778
233364
108176
698717
89882
908100
290749
186195
3123909
439280
224190
457228
336859
518134
129239
476833
354594
1657130
609260
91977
465407
143767
1144559
957261
708049
239207
326154
73942
1746132
440223
318402
534...

result:

wrong answer 1st numbers differ - expected: '172637', found: '406595'

Test #6:

score: 0
Time Limit Exceeded

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:

994739
114718
613263
270869
77515
374407
567184
46731
571742
369461
209194
76331
405378
834927
1130150
74380
76735
51166
69732
589494
485876
549313
670978
1171664
282577
78411
6304235
72410
84016
1591787
473606
218419
240192
1361283
2065153
400580
1352631
238437
45833
1840251
67639
88416
48846
13504...

result:


Test #7:

score: 0
Time Limit Exceeded

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:

66964
81683
186992
4587627
139278
92405
90437
42343
320118
221701
220928
735400
404598
253399
834072
138063
74315
48895
390429
265247
127742
190260
344821
232624
4127698
2207613
305755
144416
51209
47515
268072
90341
59011
177674
54268
669214
38702
897865
216644
139892
73848
137198
158010
116160
471...

result:


Test #8:

score: 0
Time Limit Exceeded

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:

60119
463395
56301
697439
1340794
103699
120895
485032
105196
116701
453427
2896774
3104762
65242
185784
1951911
73113
477588
738121
2040041
275248
3044216
596238
184544
870641
396470
1684113
57550
138317
205720
282160
41917
221024
827230
1491751
3554300
328111
135103
78567
232782
190203
1065860
751...

result:


Test #9:

score: 0
Time Limit Exceeded

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:

250386
57242
237199
101232
524807
451243
42093
201737
155800
108533
150017
343158
622159
396805
231987
502213
187342
120872
378497
297533
2839020
245975
135625
269125
677901
260328
71286
627459
148438
783000
875403
7382096
1040681
254054
520984
555682
1269005
107216
651811
29075
65648
224604
1223799...

result:


Test #10:

score: 0
Time Limit Exceeded

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
452477
1348956
3119412
201903
222930
1153321
3567882
124010
226902
1910592
369767
2026355
999373
847029
2187607
397398
2971393
547278
345219
3478725
1364339
129685
1431707
199174
278587
674075
455834
1492568
2716770
4772792
157986
111290
692720
67621
438775
413191
52851
1889108
505935
655668
...

result: