Submission #1056085

#TimeUsernameProblemLanguageResultExecution timeMemory
1056085manhlinh1501Autobus (COCI22_autobus)C++17
70 / 70
126 ms8284 KiB
#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 x = 2; x <= K; x++) { for(int z = 1; z <= N; z++) { for(int u = 1; u <= N; u++) { for(int v = 1; v <= N; v++) 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)

Main.cpp: In function 'int main()':
Main.cpp:15:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |         freopen(TASK ".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:16:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |         freopen(TASK ".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...