#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define mp make_pair
using namespace std;
const int mod = 1e9 + 7;
const int inf = 1e17*2;
const int N = 3e5 + 5;
int32_t main(){
int n, m;
cin>>n>>m;
int edge[n][n], dis[n][n][n*n];
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
edge[i][j] = inf;
for(int l = 0; l < n*n; l++){
dis[i][j][l] = inf;
}
}
}
for(int i = 0; i < m; i++){
int u, v, w;
cin>>u>>v>>w;
edge[u-1][v-1] = min(edge[u-1][v-1], w);
}
int k, q;
cin>>k>>q;
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
dis[i][j][1] = edge[i][j];
}
dis[i][i][1] = 0;
}
for(int asama = 2; asama < n*n; asama++){
for(int l = 0; l < n; l++){
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
dis[i][j][asama] = min(dis[i][j][asama], dis[i][l][asama-1] + dis[l][j][asama-1]);
}
}
}
}
while(q--){
int c, d;
cin>>c>>d;
c--, d--;
if(dis[c][d][min(k, n*n-1)] == inf) cout<<-1<<endl;
else cout<<dis[c][d][min(k, n-1)]<<endl;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1065 ms |
188228 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |