Submission #463695

#TimeUsernameProblemLanguageResultExecution timeMemory
463695_Avocado_Toll (BOI17_toll)C++14
18 / 100
3071 ms8372 KiB
#include <bits/stdc++.h> #define int int64_t using namespace std; vector<vector<pair<int, int>>>graph; vector<int>dijkstra(int s, int n){ priority_queue<pair<int, int>>pq; vector<int>dist(n, -1); pq.push({0, s}); while(!pq.empty()){ int d = -pq.top().first; int u = pq.top().second; pq.pop(); if(dist[u] != -1) continue; dist[u] = d; for(auto [v, w]: graph[u]){ pq.push({-(w+dist[u]), v}); } } return dist; } signed main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int k, n, m, q; cin>>k>>n>>m>>q; graph.assign(n, vector<pair<int, int>>()); for(int i = 0; i<m; ++i){ int a, b, c; cin>>a>>b>>c; graph[a].push_back({b, c}); } vector<int>zero = dijkstra(0, n); for(int i = 0; i<q; ++i){ int a, b; cin>>a>>b; if(a != 0){ vector<int>cur = dijkstra(a, n); cout<<cur[b]<<'\n'; } else cout<<zero[b]<<'\n'; } //cout<<'\n'; }

Compilation message (stderr)

toll.cpp: In function 'std::vector<long int> dijkstra(int64_t, int64_t)':
toll.cpp:21:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   21 |   for(auto [v, w]: graph[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...