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>
using namespace std;
#define endl '\n'
typedef long long ll;
int dp[75];
vector<pair<int,int>> v[75];
bool checked[75];
int n,m;
priority_queue<pair<pair<int,int>,int>,vector<pair<pair<int,int>,int>>,greater<pair<pair<int,int>,int>>> pq;
int k,q;
int main () {
ios::sync_with_stdio(0); cin.tie(0);
cin >> n >> m;
for(int i = 0; i < m; i++) {
int a,b,c; cin >> a >> b >> c;
v[a].push_back({c,b});
}
cin >> k >> q;
for(int j = 0; j < q; j++) {
int st,en; cin >> st >> en;
for(int i = 0; i < 75; i++) {
checked[i] = false;
dp[i] = -1;
}
dp[st] = 0;
pq.push({{0,st},0});
while(!pq.empty()) {
int a = pq.top().first.first;
int b = pq.top().first.second;
int cnt = pq.top().second;
pq.pop();
if(checked[b]) continue;
checked[b] = true;
if(cnt >= k) continue;
for(int i = 0; i < v[b].size(); i++) {
if(dp[v[b][i].second] == -1 || dp[v[b][i].second] > a + v[b][i].first) {
dp[v[b][i].second] = max(0,a + v[b][i].first);
pq.push({{dp[v[b][i].second],v[b][i].second},cnt+1});
}
}
}
cout << dp[en] << endl;
}
return 0;
}
Compilation message (stderr)
Main.cpp: In function 'int main()':
Main.cpp:35:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
35 | for(int i = 0; i < v[b].size(); i++) {
| ~~^~~~~~~~~~~~~
# | 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... |