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>
#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(d, 0, k - 1)
fi(t, 1, n)
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 (stderr)
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);}
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |