QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#841147#9903. 最短路径dbGIs#0 170ms6708kbC++171.7kb2025-01-03 14:24:332025-01-03 14:24:34

Judging History

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

  • [2025-01-03 14:24:34]
  • 评测
  • 测评结果:0
  • 用时:170ms
  • 内存:6708kb
  • [2025-01-03 14:24:33]
  • 提交

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=1e18+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++) dp1[i][i]={0, 1};
    for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) dp2[i][j]=LINF;
    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].S==0||dp1[i][e].F>dp1[i][x].F+a[x][e]){
                    if (dp1[i][e].S) dp2[i][e]=dp1[i][e].F;
                    dp1[i][e]={dp1[i][x].F+a[x][e], dp1[i][x].S};
                    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;
                }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();
}

Details

Tip: Click on the bar to expand more detailed information

Pretests


Final Tests

Test #1:

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

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
53781872
362303
1486937
424083
3056193
46686875
426171
1588141
53761957
424159
53777109
46612848
443840
39032539
53783213
4163602
46619498
1914167
46617038
53761883
423209
46613976
489817
38683069
428586
3059227
426171
46615196
3138905
420000
371747
2693653
46983880
1589499
1065302
53761239...

result:

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

Test #2:

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

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:

270396
2212087
5367342
1176100
2223244
121281931
28215974
64468182
248733
2129079
59349
846978
33496
2228475
2180829
1125890
122071344
3004426
28243174
15626518
1880264
1458051
322009
4315197
4316050
2216905
1336699
2223881
10907242
8094512
64472123
1024776
2165685
64442576
2163543
2266929
4521692
1...

result:

wrong answer 2nd numbers differ - expected: '334851', found: '2212087'

Test #3:

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

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
2027954
3144841
2916029
1968004
2924408
874504
2479015
2886607
1892999
2069898
608454
5886252
58209074
1925035
1943975
87127444
91338615
1929592
2561661
884057
2031078
1943975
2024811
7330925
2034722
5923913
18669172
18005450
2029516
5603240
1282703
5041582
2059238
415247
1890265
2029...

result:

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

Test #4:

score: 0
Wrong Answer
time: 87ms
memory: 6484kb

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:

2001566
70070
33848
149145
1614988
287049
138322
66529
107736
166327
218252
366116
21116
45195
4352983
66962
1972362
328792
2429250
2434878
129043
2067194
258161
59954
40781
2932938
161556
69521
387508
56485
127522
291260
1008322
352717
2001566
2112631
2156569
1368445
356333
162546
731528
2434147
31...

result:

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

Test #5:

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

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:

172637
832868
281122
174543
818244
1043804
350730
14728002
525508
113999
249428
1167232
233364
834641
64057
83069
531557
155002
186195
3123909
439280
878481
2461352
237704
518134
122426
878383
572018
1406783
284447
91977
166035
163534
245784
839008
553195
307849
139043
155521
1962713
256364
810914
2...

result:

wrong answer 2nd numbers differ - expected: '125082', found: '832868'

Test #6:

score: 0
Wrong Answer
time: 169ms
memory: 6584kb

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
256077
311552
2347565
93834
374407
531186
147959
26386
1129613
39625
301026
2338138
243782
530243
1153547
2360200
1392568
69732
5142284
101861
67494
34130
153402
146767
5160998
119518
11955268
1186655
1428843
473606
78601
373633
91369
1970063
37369
6061611
238437
43237
349161
51084
101543
2723...

result:

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

Test #7:

score: 0
Wrong Answer
time: 166ms
memory: 6488kb

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:

52439
8238536
62795
324769
158935
64214
181154
42343
90717
124066
118935
427105
37427
415792
834072
296737
1796554
38925
3705108
89128
256629
61297
123760
292022
62469
6428793
67048
128043
560921
1618856
82786
91980
232785
105607
41401
415399
119645
201212
8248037
33994
620768
37963
115682
140285
12...

result:

wrong answer 2nd numbers differ - expected: '27329', found: '8238536'

Test #8:

score: 0
Wrong Answer
time: 170ms
memory: 6584kb

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:

93779
7854198
1109370
55222
358809
72326
159271
692247
106326
99074
32081
2837458
255977
173056
220051
87276
612621
181421
584949
1761130
4152687
2854817
237014
393877
176069
289725
2811250
591216
51460
60811
8314493
41917
289451
640138
689515
2842881
110018
83125
245658
422632
174089
1241064
393556...

result:

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

Test #9:

score: 0
Wrong Answer
time: 162ms
memory: 6460kb

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:

196481
874209
3288437
1707369
42129
122823
42093
343592
3152233
108533
190225
38009
106620
37048
3113335
179256
200049
109950
171293
190248
2836862
258536
88129
908301
565899
6487056
188187
172583
1282933
342547
1286467
7211348
37469
3167516
81197
183750
1298128
199117
823072
489817
294716
3149861
1...

result:

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

Test #10:

score: 0
Wrong Answer
time: 156ms
memory: 6492kb

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
10203495
593646
848000
116158
138860
1014467
4278644
133034
320115
135959
314213
161997
14203771
651182
323937
141190
2753928
2217866
598362
8831058
414308
129685
142590
776422
108186
129611
452864
121691
458138
4713122
78210
111290
604165
67621
101468
836758
96602
266919
945748
549181
432871...

result:

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