QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#557638 | #8673. 最短路径 | DaiRuiChen007 | 0 | 2696ms | 96320kb | C++17 | 2.2kb | 2024-09-11 10:39:50 | 2024-09-11 10:39:50 |
Judging History
answer
#include<bits/stdc++.h>
#define ui unsigned
#define ll long long
using namespace std;
const int MAXN=2e5+5;
struct Edge { int v; ui w; };
struct Node {
ll d; int u,i;
friend bool operator <(const Node &x,const Node &y) { return x.d>y.d; }
};
vector <Edge> gs[MAXN],gt[MAXN];
ll ds[MAXN],dt[MAXN];
bool vs[MAXN],vt[MAXN];
ll qry(int s,int t) {
if(s==t) return 0;
if(gs[s].empty()||gt[t].empty()) return -1;
vector <int> us{s},ut{t}; ds[s]=dt[t]=0,vs[s]=vt[t]=1;
priority_queue <Node> qs,qt;
qs.push({gs[s][0].w,s,0}),qt.push({gt[t][0].w,t,0});
int z=0;
while(qs.size()&&qt.size()) {
ll d; int u,i,v;
if(qs.size()<=qt.size()) {
d=qs.top().d,u=qs.top().u,i=qs.top().i,v=gs[u][i].v,qs.pop();
if(i+1<(int)gs[u].size()) qs.push({ds[u]+gs[u][i+1].w,u,i+1});
if(vs[v]) continue;
vs[v]=true,ds[v]=d,us.push_back(v);
if(vt[v]) { z=v; break; }
if(gs[v].size()) qs.push({d+gs[v][0].w,v,0});
} else {
d=qt.top().d,u=qt.top().u,i=qt.top().i,v=gt[u][i].v,qt.pop();
if(i+1<(int)gt[u].size()) qt.push({dt[u]+gt[u][i+1].w,u,i+1});
if(vt[v]) continue;
vt[v]=true,dt[v]=d,ut.push_back(v);
if(vs[v]) { z=v; break; }
if(gt[v].size()) qt.push({d+gt[v][0].w,v,0});
}
}
if(!z) return -1;
ll ans=ds[z]+dt[z];
for(int u:us) {
ll lim=(ds[z]-ds[u])<<1;
for(auto e:gs[u]) {
if(e.w>=lim) break;
if(vt[e.v]) ans=min(ans,ds[u]+e.w+dt[e.v]);
}
}
for(int u:vs) {
ll lim=(dt[z]-dt[u])<<1;
for(auto e:gt[u]) {
if(e.w>=lim) break;
if(vs[e.v]) ans=min(ans,ds[e.v]+e.w+dt[u]);
}
}
for(int u:us) vs[u]=false;
for(int u:ut) vt[u]=false;
return ans;
}
signed main() {
ios::sync_with_stdio(false);
int n,m,q,sd; cin>>n>>m>>q>>sd;
mt19937 rnd(sd);
auto ver=[&]() {
static const ui LIM=-1u/n*n;
ui x; for(x=rnd();x>=LIM;x=rnd());
return x%n+1;
};
for(int i=1;i<=m;++i) {
int u=ver(),v=ver(); ui w=rnd();
gs[u].push_back({v,w});
gt[v].push_back({u,w});
}
for(int i=1;i<=n;++i) {
sort(gs[i].begin(),gs[i].end(),[&](auto x,auto y){ return x.w<y.w; });
sort(gt[i].begin(),gt[i].end(),[&](auto x,auto y){ return x.w<y.w; });
}
for(int s,t;q--;) cin>>s>>t,cout<<qry(s,t)<<"\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 5
Accepted
time: 0ms
memory: 15072kb
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: 4ms
memory: 15044kb
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: 0
Wrong Answer
time: 2595ms
memory: 78052kb
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:
15716615 49860181 48986450 27805775 41392651 43506617 39517515 40352182 37675345 23367579 37276839 32364058 50703016 26615083 25983590 51209814 29883096 31222991 39092809 25257238 37822632 61379702 31252941 45804995 18086930 18086930 38718065 55135658 31005342 41408425 31818407 16387257 33855505 259...
result:
wrong answer 1st lines differ - expected: '36084543', found: '15716615'
Subtask #3:
score: 0
Wrong Answer
Test #13:
score: 0
Wrong Answer
time: 201ms
memory: 25216kb
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:
wrong answer 421st lines differ - expected: '-1', found: '47979820445'
Subtask #4:
score: 0
Wrong Answer
Test #17:
score: 0
Wrong Answer
time: 69ms
memory: 30528kb
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:
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -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 1st lines differ - expected: '21671419385', found: '-1'
Subtask #5:
score: 0
Wrong Answer
Test #21:
score: 0
Wrong Answer
time: 2696ms
memory: 33552kb
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:
18098332289 22666064981 23549058925 27064793229 -1 23116762056 22209493371 21117534178 22029252897 33988361853 17793204212 13278636159 25843769632 18134229421 29623865096 23847021502 20878297870 -1 -1 21042457357 23208160613 19615484227 26566774108 15726744387 23457868594 23517057425 16578768343 242...
result:
wrong answer 4th lines differ - expected: '26339412859', found: '27064793229'
Subtask #6:
score: 0
Wrong Answer
Test #24:
score: 0
Wrong Answer
time: 393ms
memory: 94144kb
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:
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -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 1st lines differ - expected: '1547972368', found: '-1'
Subtask #7:
score: 0
Wrong Answer
Test #33:
score: 0
Wrong Answer
time: 510ms
memory: 96320kb
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:
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -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 1st lines differ - expected: '3371897180', found: '-1'