QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#558223#8673. 最短路径byron1000010 3624ms177840kbC++142.6kb2024-09-11 14:57:342024-09-11 14:57:34

Judging History

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

  • [2024-09-11 14:57:34]
  • 评测
  • 测评结果:10
  • 用时:3624ms
  • 内存:177840kb
  • [2024-09-11 14:57:34]
  • 提交

answer

#if defined(_USE_PCH_)
#include "pch.hpp"
#else
#include <bits/stdc++.h>
#endif
#define RNG(V_, A_, B_, ...) for(int V_=(A_), V_##_END=(B_) __VA_OPT__(,) __VA_ARGS__; V_<=V_##_END; V_++)
#define IRNG(V_, A_, B_) for(int V_=(A_), V_##_END=(B_); V_>=V_##_END; V_--)
#ifdef _WIN32
#define long __int64
#endif
using namespace std;
const int MAXN=2e5+10,INF=1e9; const long INFLL=0x3f3f3f3f3f3f3f3f;
int n,m,qn,seed;
vector<pair<int,long>> G[2][MAXN];
long dis[2][MAXN],vis[2][MAXN]; vector<int> vec[2];
priority_queue<tuple<long,int,int>,vector<tuple<long,int,int>>,greater<tuple<long,int,int>>> pq[2];
long solve(int st,int ed){
    RNG(t,0,1){
        for(auto u:vec[t]) dis[t][u]=INFLL,vis[t][u]=0;
        vec[t].clear(); pq[t]={};
    }
    pq[0].push({0,st,-1}),pq[1].push({0,ed,-1});
    int meet=0;
    auto step=[&meet](int t){
        auto [d,fa,i]=pq[t].top(); pq[t].pop();
        int u=i<0?fa:G[t][fa][i].first;
        vec[t].push_back(u);
        if(i>=0&&i+1<(int)G[t][fa].size()){
            i++;
            pq[t].push({dis[t][fa]+G[t][fa][i].second,fa,i});
        }
        if(dis[t][u]>d){
            dis[t][u]=d;
            assert(!vis[t][u]),vis[t][u]=1;
            if(vis[!t][u]) meet=u;
            if(G[t][u].size()) pq[t].push({dis[t][u]+G[t][u].front().second,u,0});
        }
    };
    while(pq[0].size()||pq[1].size()){
        if(pq[0].size()) step(0);
        if(pq[1].size()) step(1);
        if(meet){
            long ret=dis[0][meet]+dis[1][meet];
            int t=vec[0].size()<vec[1].size()?0:1;
            auto& vc=vec[t];
            for(auto u:vc){
                for(auto [v,w]:G[t][u]) ret=min(ret,dis[t][u]+dis[!t][v]+w);
            }
            return ret;
        }
    }
    return -1;
}
int main(){
#if defined(_LOCAL_)
    freopen("in","r",stdin);
//  freopen("out","w",stdout);
#else
//  freopen("c.in","r",stdin);
//  freopen("c.out","w",stdout);
#endif
    ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
    cin>>n>>m>>qn>>seed;
    {
        mt19937 rng(seed);
        uint64_t mx = -1u / n * n;
        auto sample = [&]()->int {
            uint64_t x;
            do { x = rng(); } while(x >= mx);
            return x % n + 1;
        };
        RNG(_,1,m){
            int u=sample(),v=sample(); long w=rng();
            G[0][u].push_back({v,w}),G[1][v].push_back({u,w});
        }
        RNG(t,0,1){
            RNG(i,1,n) sort(G[t][i].begin(),G[t][i].end(),[](auto x,auto y){ return x.second<y.second; });
        }
    }
    memset(dis,0x3f,sizeof(dis));
    RNG(_,1,qn){
        int s,t; cin>>s>>t;
        cout<<solve(s,t)<<"\n";
    }
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 5
Accepted
time: 4ms
memory: 16784kb

input:

4 8 5 1112792816
2 3
4 3
4 3
3 2
1 4

output:

3419197189
1798364963
1798364963
3986398077
2337967903

result:

ok 5 lines

Test #2:

score: 0
Wrong Answer
time: 5ms
memory: 17372kb

input:

2000 2000 2000 3336994405
659 1650
1678 341
818 235
1380 1865
1927 1366
1233 1673
267 1698
775 1022
1255 1110
1533 1928
1854 169
1579 729
449 1335
943 583
360 50
795 926
1584 911
1924 604
280 309
1429 420
1107 1858
1466 76
265 1109
1077 622
245 1941
957 1434
1560 1128
122 51
229 925
826 1006
851 323...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
...

result:

wrong answer 157th lines differ - expected: '787133140', found: '-1'

Subtask #2:

score: 0
Wrong Answer

Test #6:

score: 15
Accepted
time: 1350ms
memory: 140888kb

input:

3000 3000000 10000 37461678
2873 1368
1757 2000
1262 1822
2484 1778
2055 2096
2545 366
2923 2028
1469 1874
691 631
1173 2967
894 2020
1207 881
373 236
1913 1923
1351 16
1066 2032
471 1561
1047 2043
457 145
2728 1752
2521 1199
1568 904
2515 543
1472 2161
748 2744
748 1908
912 172
2340 2494
977 267
10...

output:

36084543
49860181
45803385
27805775
41392651
43506617
39517515
39687913
37675345
23367579
37276839
32364058
50703016
26615083
25983590
51209814
42921191
31222991
39092809
25257238
36267824
60108033
34199475
45804995
35826034
34257048
38718065
55135658
31005342
41408425
35033769
37667712
42873640
378...

result:

ok 10000 lines

Test #7:

score: 0
Wrong Answer
time: 385ms
memory: 116400kb

input:

3000 2000000 10000 2522167365
2102 2825
724 1689
2259 2561
1681 677
62 2183
2589 1214
926 1138
674 2610
1679 1607
1349 2461
2617 1599
457 2347
584 518
1506 554
2954 470
1027 893
1924 2
2624 2746
1366 2651
2236 2085
362 2871
1413 1763
2497 404
1507 1216
894 322
2221 2553
824 2374
1883 1507
2484 2504
...

output:

55342528
55342528
55342528
55342528
55342528
55342528
55342528
55342528
55342528
55342528
55342528
55342528
55342528
55342528
55342528
55342528
55342528
55342528
55342528
55342528
55342528
55342528
55342528
55342528
55342528
55342528
55342528
55342528
55342528
55342528
55342528
55342528
55342528
553...

result:

wrong answer 1st lines differ - expected: '65574243', found: '55342528'

Subtask #3:

score: 10
Accepted

Test #13:

score: 10
Accepted
time: 333ms
memory: 30092kb

input:

200000 200000 10000 1824322211
104482 112162
130667 13436
36792 142259
51832 97549
15358 180076
128251 92635
45296 195115
62109 38014
22014 86754
79735 103777
94797 96086
196760 5955
45622 59618
12995 62585
55686 156402
23085 68138
170749 148553
97603 160274
112975 22651
116322 190720
84774 57075
23...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
...

result:

ok 10000 lines

Test #14:

score: 10
Accepted
time: 28ms
memory: 25000kb

input:

200000 100000 10000 1394653802
99794 128174
196511 141958
176353 6707
19037 95308
12331 132159
47825 12373
47277 130874
165656 114428
81800 12371
165878 128160
33280 71225
139344 138789
126396 182051
103407 151857
20873 18698
155652 38063
150807 191146
57310 174863
114490 88197
158133 29636
137962 1...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
...

result:

ok 10000 lines

Test #15:

score: 10
Accepted
time: 59ms
memory: 23544kb

input:

100000 100000 10000 913053279
28316 35031
36768 9164
74111 12192
71120 23394
97477 34141
50880 24433
99500 23365
99785 571
95784 50853
8313 70744
33410 27807
29073 96498
82964 79943
32999 84423
90798 98756
98245 89258
89589 49557
90152 40866
53406 41385
33889 39018
42199 52421
13784 26639
85311 5769...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
...

result:

ok 10000 lines

Test #16:

score: 10
Accepted
time: 0ms
memory: 17952kb

input:

1 1 10000 1920830832
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 10000 lines

Subtask #4:

score: 0
Time Limit Exceeded

Test #17:

score: 0
Time Limit Exceeded

input:

200000 500000 10000 3113327438
68816 31422
174349 125983
18111 188786
84806 87249
142007 180723
95611 116398
104758 196349
77547 89859
120350 77199
110906 10209
177461 194861
115505 105566
27493 166237
15676 158290
86204 116010
159979 125659
132461 61989
194289 157721
18830 82910
166696 98162
125208...

output:


result:


Subtask #5:

score: 0
Time Limit Exceeded

Test #21:

score: 0
Time Limit Exceeded

input:

200000 500000 10000 1843053063
3409 108359
168924 184622
13119 119837
109492 38050
97152 51201
49047 12472
183998 191613
193074 177289
194248 104409
15509 88499
61967 143398
4532 56790
196650 158711
63655 70744
140178 107299
63530 87330
127334 159237
7134 184418
125289 28604
176966 179527
181695 128...

output:


result:


Subtask #6:

score: 0
Wrong Answer

Test #24:

score: 0
Wrong Answer
time: 1254ms
memory: 175044kb

input:

100000 3000000 10000 3892765041
14843 34156
43390 49542
38564 95501
26194 87126
18638 53346
69414 47011
95472 58303
44370 77172
75652 90555
94386 31888
47911 9905
70599 97061
52764 24896
31445 15589
82314 43852
97155 93412
11834 45082
75614 42459
67802 32024
82389 4968
32860 62514
97630 28012
14839 ...

output:

1869409771
1869409771
1869409771
1869409771
1869409771
1869409771
1869409771
1869409771
1869409771
1869409771
1869409771
1869409771
1869409771
1869409771
1869409771
1869409771
1869409771
1869409771
1869409771
1869409771
1869409771
1869409771
1869409771
1869409771
1869409771
1869409771
1869409771
186...

result:

wrong answer 1st lines differ - expected: '1547972368', found: '1869409771'

Subtask #7:

score: 0
Wrong Answer

Test #33:

score: 0
Wrong Answer
time: 3624ms
memory: 177840kb

input:

200000 3000000 10000 3910662331
161257 40967
50546 86049
199665 199302
177403 36274
158790 143151
193304 78511
28032 149723
96394 37099
2157 76024
195400 34830
41933 147591
191613 96468
194837 67293
57992 63117
24749 6694
117818 87323
46130 53470
174812 24950
149173 124886
119910 54123
2297 124533
5...

output:

4021896299
4021896299
4021896299
4021896299
4021896299
4021896299
4021896299
4021896299
4021896299
4021896299
4021896299
4021896299
4021896299
4021896299
4021896299
4021896299
4021896299
4021896299
4021896299
4021896299
4021896299
4021896299
4021896299
4021896299
4021896299
4021896299
4021896299
402...

result:

wrong answer 1st lines differ - expected: '3371897180', found: '4021896299'