#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
typedef long long ll;
ll dp[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;
v[a].push_back({c,b});
}
cin >> k >> q;
for(int i = 1; i <= n; i++) {
for(int j = 0; j <= n; j++) {
dp[i][j] = -1;
}
dp[i][i] = 0;
set<int> s;
pq.push({{0,i},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 = 0; j < v[b].size(); j++) {
if(dp[i][v[b][j].second] == -1) dp[i][v[b][j].second] = a + v[b][j].first;
else dp[i][v[b][j].second] = min(dp[i][v[b][j].second],a + v[b][j].first);
if(!cnt.count(v[b][j].second))pq.push({{a + v[b][j].first,v[b][j].second},cnt});
}
}
}
for(int i = 0; i < q; i++) {
int c,d; cin >> c >> d;
cout << dp[c][d] << endl;
}
return 0;
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:32:27: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
32 | if(cnt.size() >= k + 1) continue;
| ~~~~~~~~~~~^~~~~~~~
Main.cpp:33:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
33 | for(int j = 0; j < v[b].size(); j++) {
| ~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
3 ms |
340 KB |
Output is correct |
3 |
Correct |
10 ms |
468 KB |
Output is correct |
4 |
Correct |
8 ms |
448 KB |
Output is correct |
5 |
Correct |
155 ms |
992 KB |
Output is correct |
6 |
Correct |
151 ms |
1136 KB |
Output is correct |
7 |
Execution timed out |
1085 ms |
35236 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Execution timed out |
1008 ms |
524288 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
3 ms |
340 KB |
Output is correct |
9 |
Correct |
10 ms |
468 KB |
Output is correct |
10 |
Correct |
8 ms |
448 KB |
Output is correct |
11 |
Correct |
155 ms |
992 KB |
Output is correct |
12 |
Correct |
151 ms |
1136 KB |
Output is correct |
13 |
Execution timed out |
1085 ms |
35236 KB |
Time limit exceeded |
14 |
Halted |
0 ms |
0 KB |
- |