Submission #1021126

#TimeUsernameProblemLanguageResultExecution timeMemory
1021126Khanhcsp2Autobus (COCI22_autobus)C++14
70 / 70
114 ms10576 KiB
#include<bits/stdc++.h> #define el '\n' #define fi first #define sc second #define int ll #define pii pair<int, int> #define all(v) v.begin(), v.end() using namespace std; using ll=long long; using ull=unsigned long long; using ld=long double; const int mod=1e9+7; const int N=81; int n, m, q, k, adj[N][N], ans[N][N], dp[N][N][N]; void sol() { cin >> n >> m; for(int i=1; i<=n; i++) for(int j=1; j<=n; j++) if(i!=j) adj[i][j]=1e9; for(int i=0; i<=n; i++) for(int j=0; j<=n; j++) for(int l=0;l<=n;l++) dp[i][j][l]=1e9; for(int i=1; i<=m; i++) { int u, v, w; cin >> u >> v >> w; adj[u][v]=min(adj[u][v], w); } for(int i=1; i<=n; i++) dp[0][i][i]=0; for(int i=1; i<=n; i++) for(int j=1; j<=n; j++) dp[1][i][j] = adj[i][j]; cin >> k >> q; for(int i=2; i<=n; i++) { for(int j=1; j<=n; j++) { for(int x=1; x<=n; x++) { for(int y=1; y<=n; y++) { dp[i][j][x]=min(dp[i][j][x], dp[i-1][j][y]+adj[y][x]); } } } } for(int x=1; x<=n; x++) { for(int y=1; y<=n; y++) { if(x!=y) ans[x][y]=1e9; for(int i=0; i<=min(n, k); i++) { ans[x][y]=min(ans[x][y], dp[i][x][y]); } } } while(q--) { int u, v; cin >> u >> v; if(ans[u][v]==1e9) cout << -1 << el; else cout << ans[u][v] << el; } } signed main() { // freopen("divisor.INP", "r", stdin); // freopen("divisor.OUT", "w", stdout); ios_base::sync_with_stdio(0); cin.tie(0); int t=1; //cin >> t; while(t--) { sol(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...