Submission #851750

#TimeUsernameProblemLanguageResultExecution timeMemory
851750futureEvacuation plan (IZhO18_plan)C++14
23 / 100
958 ms58144 KiB
#include <bits/stdc++.h> using namespace std; int n,q; int m; vector<pair<int,int>>g[100005]; long long d[100005]; long long dd[100005]; int trc[100005]; map<pair<int,int>,bool>ok; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>n>>m; while(m--) { int u,v,c; cin>>u>>v>>c; g[u].push_back({v,c}); g[v].push_back({u,c}); ok[{u,v}]=1; } int k; cin>>k; for(int i=1; i<=n; i++)d[i]=1e18; priority_queue<pair<long long,int>,vector<pair<long long,int>>,greater<pair<long long,int>>>pq; while(k--) { int u; cin>>u; d[u]=0; pq.push({0,u}); } while(pq.size()) { auto[_,u]=pq.top(); pq.pop(); for(auto v:g[u])if(d[v.first]>d[u]+v.second) { d[v.first]=d[u]+v.second; pq.push({d[v.first],v.first}); } } int q; cin>>q; while(q--) { int s,t; cin>>s>>t; if(ok[{s,t}]||ok[{t,s}]){cout<<min(d[s],d[t])<<'\n';continue;} for(int i=1; i<=n; i++)dd[i]=1e18; priority_queue<pair<long long,int>,vector<pair<long long,int>>,greater<pair<long long,int>>>pq; dd[s]=0; pq.push({0,s}); while(pq.size()) { auto[_,u]=pq.top(); pq.pop(); for(auto v:g[u])if(dd[v.first]>dd[u]+v.second) { dd[v.first]=dd[u]+v.second; trc[v.first]=u; pq.push({dd[v.first],v.first}); } } long long ans=1e18; while(t!=s) { //cout<<t<<'\n'; ans=min(ans,d[t]); t=trc[t]; } ans=min(ans,d[s]); cout<<ans<<'\n'; } return 0; }

Compilation message (stderr)

plan.cpp: In function 'int main()':
plan.cpp:33:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   33 |         auto[_,u]=pq.top();
      |             ^
plan.cpp:51:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   51 |         auto[_,u]=pq.top();
      |             ^
#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...