Submission #864513

#TimeUsernameProblemLanguageResultExecution timeMemory
864513maks007Toll (BOI17_toll)C++14
10 / 100
3037 ms4460 KiB
// Bismi ALlah #include "bits/stdc++.h" using namespace std; signed main () { int n, m, k, query; cin >> k >> n >> m >> query; vector<pair <int,int>> g[n]; vector <int> in(n, 0); for(int i = 0; i < m; i ++) { int u, v; cin >> u >> v; int w; cin >> w; g[u].push_back({v, w}); in[v] ++; } priority_queue <pair <int,int>> q; vector <int> dist(n, 1e9); dist[0] = 0; q.push({0, 0}); while(!q.empty()) { int v = q.top().second, cur_d = q.top().first; q.pop(); if(cur_d > dist[v]) continue; for(auto [u, w] : g[v]) { if(dist[u] > dist[v] + w) { dist[u] = dist[v] + w; q.push({-dist[u], u}); } } } while(query --) { int a, b; cin >> a >> b; if(a == 0) { if(dist[b] == 1e9) cout << -1 << "\n"; else cout << dist[b] << "\n"; }else { queue <int> q; vector <int> dist2(n, -1); dist2[a] = 0; q.push(a); while(!q.empty()) { int v = q.front(); q.pop(); for(auto [u, w] : g[v]) { if(dist2[u] == -1) { dist2[u] = dist2[v] + w; q.push(u); } } } if(dist2[b] == 1e9) cout << -1 << "\n"; else cout << dist2[b] << "\n"; } } return 0; }

Compilation message (stderr)

toll.cpp: In function 'int main()':
toll.cpp:28:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   28 |   for(auto [u, w] : g[v]) {
      |            ^
toll.cpp:51:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   51 |     for(auto [u, w] : g[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...