# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
535865 |
2022-03-11T14:53:45 Z |
__Variatto |
Toll (BOI17_toll) |
C++17 |
|
73 ms |
7920 KB |
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define ll long long
const int MAX=5e4+10;
const int MAXV=1e9+10;///////////////
int k, n, m, o, a, b, w, wyn[MAX], odl[MAX];
pair<int,int>zap[MAX];
vector<pair<int,int>>g[MAX], g2[MAX];
vector<int> nrzap[MAX];
bool odw[MAX];
priority_queue<pair<int,int>>kol;
void dijkstra(int p){
while(kol.size()){
auto v=kol.top();
kol.pop();
v.fi*=-1;
if(odw[v.se]) continue;
odw[v.se]=true;
for(auto s: g[v.se])
if(s.fi/k<=p && odl[s.fi]>v.fi+s.se)
odl[s.fi]=v.fi+s.se, kol.push({-odl[s.fi], s.fi});
}
}
void dijkstra2(int l){
while(kol.size()){
auto v=kol.top();
kol.pop();
v.fi*=-1;
if(odw[v.se]) continue;
odw[v.se]=true;
for(auto s: g2[v.se])
if(s.fi/k>=l && odl[s.fi]>v.fi+s.se)
odl[s.fi]=v.fi+s.se, kol.push({-odl[s.fi], s.fi});
}
}
void rek(int a, int b){
if(a==b) return;
int sr=(a+b)/2;
for(int j=k*sr; j<k*(sr+1); j++){
for(int i=k*sr; i<k*(b+1); i++)
odw[i]=false, odl[i]=MAXV;
kol.push({0, j}), odl[j]=0;
dijkstra(b);
for(int i=k*(sr+1)-1; i>=(k*a); i--)
odw[i]=false, odl[i]=MAXV;
kol.push({0, j}), odl[j]=0;
dijkstra2(a);
if(sr==1){
cout<<j<<": "<<"\n";
for(int i=k*sr; i<k*(b+1); i++)
cout<<i<<": "<<odl[i]<<"\n";
for(int i=k*sr; i>=(k*a); i--)
cout<<i<<": "<<odl[i]<<"\n";;
cout<<"\n";
}
for(int i=k*(sr+1)-1; i>=k*a; i--){
for(auto x:nrzap[i]){
if(zap[x].se>=k*sr && zap[x].se<k*(b+1)){
cout<<x<<" "<<zap[x].se<<" "<<i<<"x "<<odl[i]<<" "<<odl[zap[x].se]<<"\n";
wyn[x]=min(wyn[x], odl[i]+odl[zap[x].se]);
}
}
}
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin>>k>>n>>m>>o;
for(int i=1; i<=m; i++){
cin>>a>>b>>w;
g[a].pb({b, w}), g2[b].pb({a, w});
}
for(int i=1; i<=o; i++){
cin>>zap[i].fi>>zap[i].se;
wyn[i]=MAXV;
nrzap[zap[i].fi].pb(i);
}
rek(0, n/k);
for(int i=1; i<=o; i++){
if(wyn[i]==MAXV)
cout<<-1<<"\n";
else
cout<<wyn[i]<<"\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
31 ms |
7920 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
73 ms |
7856 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
3796 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
3796 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
31 ms |
7920 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |