Submission #682808

#TimeUsernameProblemLanguageResultExecution timeMemory
682808iskhakkutbilimEvacuation plan (IZhO18_plan)C++14
10 / 100
4061 ms20248 KiB
#include <bits/stdc++.h> using namespace std; //#define int long long #define ff first #define ss second #define all(a) a.begin(), a.end() const int N = 1e5; const int M = 1e9; int n, m, k; vector< pair<int, int> > g[N]; int AEC[N], distanc[N]; vector<int> A, B; set< pair<int, int> > q; void dijkstra(int start, vector<int>&dis){ for(int i = 0;i < n; i++) dis[i] = (i == start ? 0 : M); q.insert({dis[start], start}); while(!q.empty()){ int v = q.begin()->ss; q.erase(q.begin()); for(auto [to, len] : g[v]){ if(dis[to] > dis[v] + len){ q.erase({dis[to], to}); dis[to] = dis[v]+len; q.insert({dis[to], to}); if(AEC[start]==0 and AEC[to] == 1){ distanc[start] = min(distanc[start], dis[to]); } if(AEC[start]==1 and AEC[to] == 0){ distanc[to] = min(distanc[to], dis[to]); } } } } } main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m; for(int i = 0;i < m; i++){ int a, b, w; cin >> a >> b >> w; a--, b--; g[a].push_back({b, w}); g[b].push_back({a, w}); } vector<int> dis(n); cin >> k; for(int i = 0;i < k; i++){ int a; cin >> a; a--; AEC[a] = 1; } for(int i = 0;i < n; i++){ distanc[i] = M; if(AEC[i] == 0) B.push_back(i); else A.push_back(i); } if(k > (int)sqrt(n)){ for(int start : B){ dijkstra(start, dis); } }else{ for(int start : A){ dijkstra(start, dis); } } int Q; cin >> Q; while(Q--){ int a, b; cin >> a >> b; a--, b--; if(AEC[a] == 1 or AEC[b] == 1){ cout << 0 << '\n'; }else{ cout << min(distanc[a], distanc[b]) << '\n'; } } return 0; }

Compilation message (stderr)

plan.cpp: In function 'void dijkstra(int, std::vector<int>&)':
plan.cpp:23:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   23 |   for(auto [to, len] : g[v]){
      |            ^
plan.cpp: At global scope:
plan.cpp:41:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   41 | main(){
      | ^~~~
#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...