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;
ll dp[75][75];
ll path[75][75];
//vector<pair<ll,ll>> v[75];
//bool checked[75];
int n,m;
//priority_queue<pair<pair<ll,ll>,set<int>>,vector<pair<pair<ll,ll>,set<int>>>,greater<pair<pair<ll,ll>,set<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++) {
ll a,b,c; cin >> a >> b >> c;
if(path[a][b] == 0 || path[a][b] > c) path[a][b] = c;
}
cin >> k >> q;
for(int i = 1; i <= n; i++) {
for(int j = 0; j <= n; j++) {
dp[i][j] = -1;
}
}
for(int i = 0; i < q; i++) {
int c,d; cin >> c >> d;
priority_queue<pair<pair<ll,ll>,set<int>>,vector<pair<pair<ll,ll>,set<int>>>,greater<pair<pair<ll,ll>,set<int>>>> pq;
dp[c][c] = 0;
if(dp[c][d] != -1) {
cout << dp[c][d] << endl;
continue;
}
set<int> s;
pq.push({{0,c},s});
while(!pq.empty()) {
ll a = pq.top().first.first;
ll b = pq.top().first.second;
set<int> cnt = pq.top().second;
pq.pop();
cnt.insert(b);
if(cnt.size() >= k + 1) continue;
for(int j = 1; j <= n; j++) {
if(path[b][j] != 0) {
if(dp[c][j] == -1) dp[c][j] = a + path[b][j];
else dp[c][j] = min(dp[c][j], a + path[b][j]);
if(!cnt.count(j))pq.push({{a + path[b][j],j},cnt});
}
}
}
cout << dp[c][d] << endl;
}
return 0;
}
Compilation message (stderr)
Main.cpp: In function 'int main()':
Main.cpp:41:27: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
41 | if(cnt.size() >= k + 1) continue;
| ~~~~~~~~~~~^~~~~~~~
# | 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... |