#include <bits/stdc++.h>
#define Alora "cownav"
#define fi(i,a,b) for(int i = a; i <= b; i++)
#define fid(i,a,b) for(int i = a; i >= b; i--)
#define ll long long
#define f first
#define se second
#define pii pair<int, int>
#define getbit(i, j) ((i >> j) & 1)
#define all(v) v.begin(), v.end()
#define pb push_back
#define maxn 75
const int M = 1e9 + 7;
using namespace std;
int n, m, k, q;
ll dp[maxn][maxn][maxn];
int main(){
ios_base::sync_with_stdio(0);
cin.tie(NULL);
if(fopen(Alora".inp", "r")){
freopen(Alora".inp", "r", stdin);
freopen(Alora".out", "w", stdout);}
cin >> n >> m;
memset(dp, 60, sizeof(dp));
fi(i, 1, n) dp[0][i][i] = 0;
fi(i, 1, m){
int a, b, c;
cin >> a >> b >> c;
dp[1][a][b] = min(dp[1][a][b], 1ll*c);
}
cin >> k >> q;
k = min(k, n - 1);
fi(t, 1, n)
fi(d, 0, k - 1)
fi(u, 1, n)
fi(v, 1, n)
dp[d + 1][u][v] = min(dp[d + 1][u][v], dp[d][u][t] + dp[1][t][v]);
while(q--){
int u, v; cin >> u >> v;
ll ans = 1e18;
fi(d, 0, k) ans = min(ans, dp[d][u][v]);
if(ans != 1e18) cout << ans << '\n';
else cout << -1 << '\n';
}
return 0;
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:21:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
21 | freopen(Alora".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:22:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
22 | freopen(Alora".out", "w", stdout);}
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
3676 KB |
Output is correct |
2 |
Incorrect |
1 ms |
3652 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3676 KB |
Output is correct |
2 |
Correct |
2 ms |
3676 KB |
Output is correct |
3 |
Incorrect |
4 ms |
3676 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
3676 KB |
Output is correct |
2 |
Incorrect |
1 ms |
3652 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
3676 KB |
Output is correct |
2 |
Incorrect |
1 ms |
3652 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |