Submission #978092

#TimeUsernameProblemLanguageResultExecution timeMemory
978092SeenSiravitEvacuation plan (IZhO18_plan)C++14
54 / 100
4050 ms27524 KiB
#include<bits/stdc++.h> using namespace std; const int mxN = 1e5 + 5; int n,m,k; vector<pair<int,int>> g[mxN]; bool npp[mxN]; int dis[mxN]; void dijkstra(){ for(int i=1;i<=n;i++) dis[i] = INT_MAX; priority_queue<pair<int,int> , vector<pair<int,int>> , greater<pair<int,int>>> pq; for(int node=1;node<=n;node++){ if(npp[node]){ dis[node] = 0; pq.push({dis[node] , node}); } } while(!pq.empty()){ int u = pq.top().second; int w = pq.top().first; pq.pop(); if(dis[u] < w) continue; for(auto [v , cost] : g[u] ){ if(dis[v] > w + cost){ dis[v] = w + cost; pq.push({dis[v] , v}); } } } } int dis2[mxN]; void solve(int start_node , int end_node){ // start_node or end_node is npp if(npp[start_node] || npp[end_node]){ cout<< 0 << "\n"; return ; } // direct road for(auto [v , cost] : g[start_node]){ if(v == end_node){ cout<< min(dis[start_node] , dis[end_node]) << "\n"; return ; } } for(int i=1;i<=n;i++) dis2[i] = 0; dis2[start_node] = dis[start_node]; priority_queue<pair<int,int>> pq; pq.push({dis2[start_node] , start_node}); while(!pq.empty()){ int u = pq.top().second; int w = pq.top().first; pq.pop(); if(dis2[u] > w) continue; if(u == end_node){ cout<< dis2[u] << "\n"; return ; } for(auto [v , cost] : g[u]){ if(dis2[v] < min(w , dis[v])){ dis2[v] = min(w , dis[v]); pq.push({dis2[v] , v}); } } } cout<< 0 << "\n"; } int main(){ ios::sync_with_stdio(0),cin.tie(0); cin>> n >> m; for(int i=0;i<m;i++){ int u,v,w; cin>> u >> v >> w; g[u].push_back({v,w}); g[v].push_back({u,w}); } cin>> k; for(int i=1;i<=n;i++) npp[i] = false; for(int i=0;i<k;i++){ int node; cin>> node; npp[node] = true; } dijkstra(); // for(int i=1;i<=n;i++) cout<< dis[i] << " "; // cout<< "\n"; int q; cin>> q; while(q--){ int start_node , end_node; cin>> start_node >> end_node; solve(start_node , end_node); } return 0; }

Compilation message (stderr)

plan.cpp: In function 'void dijkstra()':
plan.cpp:32:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   32 |         for(auto [v , cost] : g[u] ){
      |                  ^
plan.cpp: In function 'void solve(int, int)':
plan.cpp:52:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   52 |     for(auto [v , cost] : g[start_node]){
      |              ^
plan.cpp:78:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   78 |         for(auto [v , cost] : g[u]){
      |                  ^
#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...