Submission #535847

#TimeUsernameProblemLanguageResultExecution timeMemory
535847new_accToll (BOI17_toll)C++14
100 / 100
264 ms19268 KiB
#include<bits/stdc++.h> #define fi first #define se second using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vl; const int N=1e5+10; vi zap[N],war[N]; int z[N]; vector<pair<int,int> >graf[2][N]; int odl[2][N],n,m,ans[N]; void bfs(int p,bool xd,int w,int kon){ vector<int> curr; curr.push_back(p); odl[xd][p]=0; while(curr.size() and w!=kon){ vi nxt; for(auto v:curr){ for(auto [u,c]:graf[xd][v]){ if(odl[xd][u]==-1) odl[xd][u]=odl[xd][v]+c,nxt.push_back(u); else odl[xd][u]=min(odl[xd][u],odl[xd][v]+c); } } if(xd) w--; else w++; curr=nxt; } } void dc(int p=0,int k=n/m){ if(p==k) return; int sr=(p+k)>>1; for(auto curr:war[sr]){ for(int i=p;i<=k;i++) for(auto xd:war[i]) odl[1][xd]=-1,odl[0][xd]=-1; bfs(curr,0,sr,k); bfs(curr,1,sr,p); for(int i=p;i<=sr;i++){ for(auto xd:war[i]){ for(auto u:zap[xd]) if(z[u]/m>sr and z[u]/m<=k and odl[1][xd]!=-1 and odl[0][z[u]]!=-1) ans[u]=min(ans[u],odl[1][xd]+odl[0][z[u]]); } } } dc(p,sr),dc(sr+1,k); } void solve(){ int kr,q; cin>>m>>n>>kr>>q; for(int i=1;i<=kr;i++){ int a,b,c; cin>>a>>b>>c; graf[0][a].push_back({b,c}),graf[1][b].push_back({a,c}); } for(int i=0;i<n;i++) war[i/m].push_back(i); for(int i=1;i<=q;i++){ int a,b; cin>>a>>b; ans[i]=INT_MAX; z[i]=b,zap[a].push_back(i); } for(int i=1;i<=n;i++) odl[0][i]=-1; dc(); for(int i=1;i<=q;i++) cout<<(ans[i]==INT_MAX?-1:ans[i])<<"\n"; } int main(){ ios_base::sync_with_stdio(0),cin.tie(0); solve(); }

Compilation message (stderr)

toll.cpp: In function 'void bfs(int, bool, int, int)':
toll.cpp:20:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   20 |    for(auto [u,c]:graf[xd][v]){
      |             ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...