# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1056082 | manhlinh1501 | Autobus (COCI22_autobus) | C++17 | 3 ms | 1884 KiB |
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>
using namespace std;
using i64 = long long;
const int MAXN = 75;
const int oo32 = 1e9;
int N, M, K, Q;
int dp[MAXN][MAXN][MAXN];
int w[MAXN][MAXN];
signed main() {
#define TASK "code"
if (fopen(TASK ".inp", "r")) {
freopen(TASK ".inp", "r", stdin);
freopen(TASK ".out", "w", stdout);
}
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> N >> M;
for(int i = 1; i <= N; i++) {
for(int j = 1; j <= N; j++) {
w[i][j] = oo32;
}
}
for(int i = 1; i <= N; i++) {
for(int j = 1; j <= N; j++) {
for(int z = 0; z <= N; z++)
dp[i][j][z] = oo32;
}
}
for(int i = 1; i <= M; i++) {
int u, v, x;
cin >> u >> v >> x;
dp[u][v][1] = min(dp[u][v][1], x);
w[u][v] = min(w[u][v], x);
}
cin >> K >> Q;
K = min(K, N - 1);
for(int i = 1; i <= N; i++) dp[i][i][0] = 0;
for(int z = 1; z <= N; z++) {
for(int u = 1; u <= N; u++) {
for(int v = 1; v <= N; v++) {
for(int x = 2; x <= K; x++)
dp[u][v][x] = min(dp[u][v][x], dp[u][z][x - 1] + w[z][v]);
}
}
}
while(Q--) {
int u, v;
cin >> u >> v;
int ans = oo32;
for(int i = 0; i <= K; i++)
ans = min(ans, dp[u][v][i]);
cout << (ans == oo32 ? -1 : ans) << "\n";
}
return (0 ^ 0);
}
Compilation message (stderr)
# | 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... |