Submission #556046

#TimeUsernameProblemLanguageResultExecution timeMemory
556046new_accAutobus (COCI22_autobus)C++14
70 / 70
210 ms8912 KiB
#include<bits/stdc++.h> #define fi first #define se second #define pitem item* using namespace std; typedef long long ll; typedef unsigned long long ull; typedef vector<int> vi; typedef vector<ll> vl; const int N=100; const int SS=1<<19; const int INFi=2e9; const ll INFl=1e13; const ll mod2=998244353; const ll mod=1e9+7; const ll mod3=1000696969; const ll p=70032301; const ull p2=913; const int L=20; int t[N],odl[N][N],dp[N][N][N]; void solve(){ int n,m; cin>>n>>m; for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) odl[i][j]=-1; for(int a,b,c,i=1;i<=m;i++){ cin>>a>>b>>c; if(odl[a][b]==-1) odl[a][b]=c; else odl[a][b]=min(odl[a][b],c); } for(int i=1;i<=n;i++) odl[i][i]=0; int k,q; cin>>k>>q; k=min(k,n); for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) dp[i][j][0]=odl[i][j]; for(int il=1;il<=n;il++){ for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ dp[i][j][il]=-1; for(int sr=1;sr<=n;sr++){ if(dp[i][sr][il-1]!=-1 and odl[sr][j]!=-1){ if(dp[i][j][il]==-1) dp[i][j][il]=dp[i][sr][il-1]+odl[sr][j]; else dp[i][j][il]=min(dp[i][j][il],dp[i][sr][il-1]+odl[sr][j]); } } } } } while(q--){ int a,b; cin>>a>>b; cout<<dp[a][b][k-1]<<"\n"; } } int main(){ ios_base::sync_with_stdio(0),cin.tie(0); int tt=1; while(tt--) solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...