# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1056082 | 2024-08-13T07:42:00 Z | manhlinh1501 | Autobus (COCI22_autobus) | C++17 | 3 ms | 1884 KB |
#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
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 348 KB | Output is correct |
2 | Incorrect | 0 ms | 348 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 1884 KB | Output is correct |
2 | Correct | 2 ms | 1884 KB | Output is correct |
3 | Incorrect | 2 ms | 1880 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 348 KB | Output is correct |
2 | Incorrect | 0 ms | 348 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 348 KB | Output is correct |
2 | Incorrect | 0 ms | 348 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |