#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define int ll
const ll mod = 1e9 + 7 , N = 71;
int n , m , k , q;
vector<pair<int , int>> G[N];
vector<vector<int>> v(N , vector<int>(N)) , d(N , vector<int>(N));
vector<int> f;
void dfs(int v , int r = 0){
if(r >= k) return;
for(auto [to , c] : G[v]){
if(f[to] == -1 || f[to] > f[v] + c){
f[to] = f[v] + c;
dfs(to , r + 1);
}
}
}
main(){
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
for(int i = 1;i < N;i ++){
for(int j = 1;j < N;j ++) v[i][j] = LLONG_MAX;
}
cin >> n >> m;
for(int i = 1;i <= m;i ++){
int u , V , t;cin >> u >> V >> t;
v[u][V] = min(v[u][V] , t);
}
for(int i = 1;i <= n;i ++){
for(int j = 1;j <= n;j ++){
if(v[i][j] != LLONG_MAX) G[i].pb({j , v[i][j]});
}
}
cin >> k >> q;
for(int i = 1;i <= n;i ++){
f = vector<int>(N , -1);
f[i] = 0;
dfs(i);
d[i] = f;
}
while(q --){
int c , D;cin >> c >> D;
cout << d[c][D] << endl;
}
}
Compilation message
Main.cpp: In function 'void dfs(long long int, long long int)':
Main.cpp:21:11: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
21 | for(auto [to , c] : G[v]){
| ^
Main.cpp: At global scope:
Main.cpp:29:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
29 | main(){
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
380 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
340 KB |
Output is correct |
2 |
Incorrect |
8 ms |
440 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
380 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
380 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |