Submission #897237

#TimeUsernameProblemLanguageResultExecution timeMemory
897237SalihSahinAutobus (COCI22_autobus)C++14
0 / 70
54 ms3156 KiB
#include<bits/stdc++.h> #define int long long #define pb push_back #define mp make_pair using namespace std; const int mod = 1e9 + 7; const int inf = 1e17*2; const int N = 3e5 + 5; int32_t main(){ int n, m; cin>>n>>m; vector<vector<int> > edge(n, vector<int>(n, inf)); for(int i = 0; i < m; i++){ int u, v, w; cin>>u>>v>>w; edge[u-1][v-1] = min(edge[u-1][v-1], w); } int k, q; cin>>k>>q; int dis[n][n][n]; for(int i = 0; i < n; i++){ for(int j = 0; j < n; j++){ for(int l = 0; l < n; l++){ dis[i][j][l] = inf; } } } for(int i = 0; i < n; i++){ for(int j = 0; j < n; j++){ dis[i][j][1] = edge[i][j]; } dis[i][i][1] = 0; } for(int asama = 2; asama < n; asama++){ for(int l = 0; l < n; l++){ for(int i = 0; i < n; i++){ for(int j = 0; j < n; j++){ dis[i][j][asama] = min(dis[i][j][asama], dis[i][l][asama-1] + dis[l][j][asama-1]); } } } } while(q--){ int c, d; cin>>c>>d; c--, d--; if(dis[c][d][min(k, n-1)] == inf) cout<<-1<<endl; else cout<<dis[c][d][min(k, n-1)]<<endl; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...