Submission #707586

#TimeUsernameProblemLanguageResultExecution timeMemory
707586Trisanu_DasAutobus (COCI22_autobus)C++17
0 / 70
11 ms1620 KiB
#include <bits/stdc++.h> using namespace std; const int INF=1e9; int n, m, k, q, adj[70][70], dp[70][70][70]; int main(){ cin >> n >> m; memset(adj, INT_MAX, sizeof(adj)); for(int i = 0; i < n; i++) adj[i][i] = 0; while(m--){ int u, v, w; cin >> u >> v >> w; adj[u - 1][v - 1] = min(adj[u - 1][v - 1], w); } cin >> k >> q; k = (k > n - 1) ? n - 1 : k; memset(dp, 0x3f, sizeof(dp)); for (int i=0; i<n; ++i) for (int j=0; j<n; ++j) { dp[0][i][j]=i==j?0:INF; dp[1][i][j] = adj[i][j]; } for(int i = 2; i < k + 1; i++) for(int u = 0; u < n; u++) for(int u2 = 0; u2 < n; u2++) for(int v = 0; v < n; v++) dp[i][u][v] = min(dp[i][u][v], dp[i - 1][u][u2] + adj[u2][v]); while(q--) { int a, b; cin >> a >> b, --a, --b; cout << (dp[k][a][b]>=INF?-1:dp[k][a][b]) << "\n"; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...