QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#841213#9903. 最短路径dbGIs#0 163ms6832kbC++141.9kb2025-01-03 15:18:542025-01-03 15:18:55

Judging History

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

  • [2025-01-03 15:18:55]
  • 评测
  • 测评结果:0
  • 用时:163ms
  • 内存:6832kb
  • [2025-01-03 15:18:54]
  • 提交

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=5e16+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]={LINF, 0};
    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};
    priority_queue<pll, vector<pll>, greater<pll>> pq;
    for(int i=1;i<=n;i++){
        pq.push({0, i});
        while(!pq.empty()){
            auto [dis, x]=pq.top();
            pq.pop();
            if (dis!=dp1[i][x].F) continue;
            for(int e=1;e<=n;e++) if (x!=e){
                if (dp1[i][e].F>(dp1[i][x].F+a[x][e])){
                    dp2[i][e]=dp1[i][e].F;
                    dp1[i][e]={dp1[i][x].F+a[x][e], dp1[i][x].S};
                    dp2[i][e]=min(dp2[i][e], dp2[i][x]+a[x][e]);
                    pq.push({dp1[i][e].F, e});
                }else if (dp1[i][e].F==(dp1[i][x].F+a[x][e])){
                    dp1[i][e].S+=dp1[i][x].S;
                    dp2[i][e]=min(dp2[i][e], dp2[i][x]+a[x][e]);
                }else{
                    dp2[i][e]=min(dp2[i][e], (dp1[i][x].F+a[x][e]));
                }
            }
        }
    }
    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: 6ms
memory: 5876kb

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:

64850474
128648
362303
1476896
91572
1463718
573771
98166
989861
350083
96154
130621
499744
443840
452272
438215
4163602
506394
846380
132338
362428
95204
500872
417193
107308
100581
1454333
98166
130496
1534011
91995
350980
2693653
454411
983703
1065302
361784
104040
415286
64939201
129792
435604
1...

result:

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

Test #2:

score: 0
Wrong Answer
time: 6ms
memory: 4844kb

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:

268920
334851
67162
107726
67266
68363
296189
41789
248733
487395
57694
846978
33496
385359
2180829
484897
2403220
1127190
270099
15626518
888813
1458051
303768
1143510
1144363
339669
523176
67903
1123934
6982613
45730
366670
524001
991593
521859
107295
879427
15945482
16084709
104072
525104
798455
...

result:

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

Test #3:

score: 0
Wrong Answer
time: 6ms
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:

2561993
829817
686787
3144841
2916029
966291
2924408
874504
2004326
2550089
397933
2069898
478031
4166690
58209074
1616486
1601337
4383706
91338615
1924533
2561661
884057
679670
1601337
683644
2663959
553878
979715
175115
470531
688349
616951
1258096
1019377
2059238
226956
708799
687921
1987437
1319...

result:

wrong answer 2nd numbers differ - expected: '1093019', found: '829817'

Test #4:

score: 0
Wrong Answer
time: 83ms
memory: 6832kb

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:

162943
70070
33848
46816
1398593
287049
127953
66529
66167
106158
207718
113053
21116
45195
41673
66962
121072
75263
46173
51801
92881
147121
44881
59954
30412
553553
80917
67026
137671
46116
91360
52185
87037
188914
162943
55155
325662
710708
266202
152177
68816
51070
56279
60852
13097
61192
127498...

result:

wrong answer 1st numbers differ - expected: '164487', found: '162943'

Test #5:

score: 0
Wrong Answer
time: 79ms
memory: 6580kb

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
120815
30994
106657
355322
346979
176889
107944
83076
205596
77879
79084
106938
55421
59810
121078
90437
138844
67282
439280
166894
154808
181590
95058
74005
111583
187234
1391006
54325
60155
133866
93543
79958
104119
130119
187237
132933
73942
134664
79010
106470
156056
180046
630183
...

result:

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

Test #6:

score: 0
Wrong Answer
time: 153ms
memory: 6524kb

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:

52652
41019
33982
132758
48351
45950
29590
39020
26386
45343
39625
68043
69447
112760
65476
62186
53405
50382
69732
204091
73897
53895
34130
44871
113426
425583
31331
36682
48589
18152
396774
26260
57011
91369
64654
37369
55051
39901
41033
228810
51084
20019
22262
28825
82267
134695
57415
99393
3485...

result:

wrong answer 1st numbers differ - expected: '994739', found: '52652'

Test #7:

score: 0
Wrong Answer
time: 161ms
memory: 6760kb

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:

52376
36900
62795
39978
132871
64214
54794
42343
50556
48060
53479
52273
37427
40614
684321
61249
66826
38925
36501
89128
71597
35712
84314
98242
40607
57614
67048
93970
234497
47034
72191
41951
59011
31769
41401
36425
38702
140455
42080
33994
39859
37963
113518
59342
97281
200376
64483
79903
281782...

result:

wrong answer 1st numbers differ - expected: '52439', found: '52376'

Test #8:

score: 0
Wrong Answer
time: 163ms
memory: 6568kb

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:

88893
241421
56301
47130
50060
29097
159271
245670
102254
63263
32081
2837458
149652
41368
65080
44721
49724
108209
67884
1761130
244750
2854817
213854
45934
150221
247081
785882
55146
40367
60811
649016
34322
224382
250816
34921
2496878
110018
83125
59980
388967
134288
144073
127607
68073
28529
512...

result:

wrong answer 1st numbers differ - expected: '54159', found: '88893'

Test #9:

score: 0
Wrong Answer
time: 160ms
memory: 6528kb

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:

43911
37514
238640
54205
36302
24818
36795
343592
102436
63044
190225
38009
74786
37048
89827
179256
181158
85761
115530
59230
38179
99402
81757
80175
477729
142985
27075
36270
50667
82067
41379
97035
37469
45064
81197
41241
62244
37222
303336
31295
294716
106248
87654
75067
128458
85649
41452
10301...

result:

wrong answer 1st numbers differ - expected: '177525', found: '43911'

Test #10:

score: 0
Wrong Answer
time: 151ms
memory: 6504kb

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:

113041
42972
477850
437149
92889
129493
650223
3566358
132960
128366
135959
283051
161997
532391
349366
227657
141190
2690686
396154
65479
117058
68068
129685
64776
128879
81699
112101
452864
103270
377369
4704319
78210
111290
548090
67621
81541
67281
96602
155074
945748
112118
3523364
145692
47135
...

result:

wrong answer 2nd numbers differ - expected: '140362', found: '42972'