This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define int int64_t
using namespace std;
vector<vector<pair<int, int>>>graph;
vector<vector<int>>dist;
void dijkstra(int s){
priority_queue<pair<int, int>>pq;
pq.push({0, s});
while(!pq.empty()){
int d = -pq.top().first;
int u = pq.top().second;
pq.pop();
if(dist[s][u] != -1) continue;
dist[s][u] = d;
for(auto [v, w]: graph[u]){
pq.push({-(w+dist[s][u]), v});
}
}
}
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>>());
dist.assign(n, vector<int>(n, -1));
for(int i = 0; i<m; ++i){
int a, b, c; cin>>a>>b>>c;
graph[a].push_back({b, c});
}
for(int i = 0; i<n; ++i){
dijkstra(i);
}
for(int i = 0; i<q; ++i){
int a, b; cin>>a>>b;
cout<<dist[a][b]<<'\n';
}
//cout<<'\n';
}
Compilation message (stderr)
toll.cpp: In function 'void dijkstra(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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |