제출 #868020

#제출 시각아이디문제언어결과실행 시간메모리
868020SalihSahinAutobus (COCI22_autobus)C++17
30 / 70
1045 ms9396 KiB
#include<bits/stdc++.h> #define pb push_back #define mp make_pair #define int long long using namespace std; const int mod = 998244353; const int N = 2e5 + 5; const int inf = 1e15 + 5; int32_t main(){ cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false); int n, m; cin>>n>>m; int edge[n][n]; for(int i = 0; i < n; i++){ for(int j = 0; j < n; j++){ edge[i][j] = inf; } } for(int i = 0; i < m; i++){ int a, b, c; cin>>a>>b>>c; a--, b--; edge[a][b] = min(edge[a][b], c); } int mndis[n][n]; int k, q; cin>>k>>q; k = min(k, n); int dis[n][n][k+1]; for(int i = 0; i < n; i++){ for(int j = 0; j < n; j++){ for(int l = 0; l <= k; 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]; } for(int len = 0; len <= k; len++){ dis[i][i][len] = 0; } } for(int len = 2; len <= k; len++){ for(int i = 0; i < n; i++){ for(int j = 0; j < n; j++){ for(int kk = 0; kk < n; kk++){ for(int lenf = 0; lenf <= len; lenf++){ dis[i][j][len] = min(dis[i][j][len], dis[i][kk][lenf] + dis[kk][j][len - lenf]); } } } } } for(int i = 0; i < n; i++){ for(int j = 0; j < n; j++){ int ans = inf; for(int len = 0; len <= k; len++){ ans = min(ans, dis[i][j][len]); } mndis[i][j] = ans; } } while(q--){ int a, b; cin>>a>>b; a--, b--; if(mndis[a][b] < inf) cout<<mndis[a][b]<<endl; else cout<<-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...