QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#735667 | #9569. Subway | as_lyr | WA | 36ms | 161544kb | C++14 | 1.9kb | 2024-11-11 21:11:36 | 2024-11-11 21:11:36 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=210000;
const ll INF=1e18;
int n,m;
int a[N],b[N];
int t,to[N],id[N];
vector <pair<int,int>> e[N];
vector <int> v[N];
deque <int> st[N];
int stp[N];
ll dis[N];
bool vis[N];
ll ans[N];
inline ll calc(int x,int y){
return dis[x]+1ll*a[id[y]]*b[id[x]];
}
int main(){
scanf("%d%d",&n,&m);
for(int i=1;i<=m;i++)
scanf("%d",&a[i]);
for(int i=1;i<=m;i++)
scanf("%d",&b[i]);
for(int i=1;i<=m;i++){
int siz;
scanf("%d",&siz);
int lst;
{
int x;
scanf("%d",&x);
t++,to[t]=x,id[t]=i;
v[x].push_back(t);
lst=t;
}
for(int j=2;j<=siz;j++){
int w,x;
scanf("%d%d",&w,&x);
t++,to[t]=x,id[t]=i;
e[lst].push_back(make_pair(t,w));
v[x].push_back(t);
lst=t;
}
}
for(int i=1;i<=n;i++){
sort(v[i].begin(),v[i].end(),[](const int x,const int y){
return b[id[x]]<b[id[y]];
});
}
priority_queue <pair<ll,int>,vector<pair<ll,int>>,greater<pair<ll,int>>> pq;
for(int i=1;i<=t;i++)
if(to[i]==1)
pq.push(make_pair(0,i));
else
dis[i]=INF;
for(int i=1;i<=n;i++)
ans[i]=INF;
while(pq.empty()==0){
int x=pq.top().second;
pq.pop();
if(vis[x])
continue;
vis[x]=1;
int i=to[x];
ans[i]=min(ans[i],dis[x]);
while(stp[i]<(int)v[i].size()&&vis[v[i][stp[i]]])
stp[i]++;
if(stp[i]<(int)v[i].size()){
int y=v[i][stp[i]];
while(stp[i]<(int)v[i].size()&&st[i].empty()==0&&calc(x,y)<calc(st[i].back(),y))
st[i].pop_back();
st[i].push_back(x);
while(st[i].size()>1&&calc(st[i][0],y)>calc(st[i][1],y))
st[i].pop_front();
if(calc(st[i][0],y)<dis[y])
pq.push(make_pair(dis[y]=calc(st[i][0],y),y));
}
for(auto pr:e[x]){
int y=pr.first,z=pr.second;
if(dis[x]+z<dis[y])
pq.push(make_pair(dis[y]=dis[x]+z,y));
}
}
for(int i=2;i<=n;i++)
printf("%lld ",ans[i]);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 22ms
memory: 159452kb
input:
6 3 1 5 1 5 5 1 3 1 2 2 3 3 3 5 1 2 1 4 3 3 4 5 4 6
output:
2 5 21 14 18
result:
ok 5 number(s): "2 5 21 14 18"
Test #2:
score: 0
Accepted
time: 36ms
memory: 159216kb
input:
6 3 1 5 1 5 5 1 5 1 2 2 100 3 100 6 1 4 5 1 100 2 4 3 100 5 1 4 2 3 1 5
output:
2 31 43 37 136
result:
ok 5 number(s): "2 31 43 37 136"
Test #3:
score: 0
Accepted
time: 27ms
memory: 157152kb
input:
5 9 278281 70119 511791 834898 25300 63487 609134 236836 394497 835557 287345 579404 879128 636344 306393 569430 152565 47119 2 3 823004250 4 2 1 25427550 3 2 1 15849621 3 2 1 701911826 5 3 5 679672631 3 907176714 2 2 1 817370554 2 2 3 697987914 2 2 4 873900795 2 2 1 814305954 5
output:
817370554 15849621 80811085745 701911826
result:
ok 4 number(s): "817370554 15849621 80811085745 701911826"
Test #4:
score: 0
Accepted
time: 23ms
memory: 159196kb
input:
5 10 436148 103565 528276 212202 680282 92724 609031 560815 80390 406327 546832 581372 731920 348686 791433 98906 112247 118131 361076 724950 4 1 213029090 4 415633732 5 581145231 3 2 4 306227294 2 2 1 713116112 4 2 3 99672714 5 2 3 975143846 1 5 4 249118026 5 689334413 1 597093740 2 553624319 3 3 4...
output:
597093740 765908995 213029090 628662822
result:
ok 4 number(s): "597093740 765908995 213029090 628662822"
Test #5:
score: 0
Accepted
time: 19ms
memory: 159216kb
input:
3 5 696710 837216 390019 431068 960618 589388 829806 692481 154511 282620 2 1 711629163 3 2 1 781784306 3 2 1 686636041 3 2 3 794790206 2 2 1 844212542 2
output:
844212542 686636041
result:
ok 2 number(s): "844212542 686636041"
Test #6:
score: -100
Wrong Answer
time: 24ms
memory: 161544kb
input:
3 8 344877 101098 328614 735002 476606 635558 573861 261083 964379 333960 25186 276560 258996 683650 765559 582374 2 3 838262394 1 2 2 863940316 3 2 2 476918371 3 3 3 320092619 1 400754003 2 3 3 150885055 2 90507792 1 2 3 190275693 2 2 2 600234969 3 2 2 679446528 3
output:
400754003 91759160214
result:
wrong answer 2nd numbers differ - expected: '29224357199', found: '91759160214'