Submission #872672

#TimeUsernameProblemLanguageResultExecution timeMemory
872672HossamHero7Autobus (COCI22_autobus)C++14
55 / 70
1027 ms194384 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define endl '\n' int edge[71][71]; vector<pair<int,int>> adj[71]; ll dp[71][71][70*70+1]; int K; ll solve(int i,int j,int k){ if(i == j) return 0; if(k == K) return 1e18; ll &ret = dp[i][j][k]; if(~ret) return ret; ret = 1e18; for(auto [ch,c] : adj[i]) ret = min(ret,solve(ch,j,k+1)+c); return ret; } void solve(){ int n,m; cin>>n>>m; for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) edge[i][j] = 1e9; for(int i=0;i<m;i++){ int a,b,c; cin>>a>>b>>c; edge[a][b] = min(edge[a][b] , c); } int cnt = 0; for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++) { if(edge[i][j] != 1e9) adj[i].push_back({j,edge[i][j]}) , cnt++; } } int q; cin>>K>>q; K = min(K,cnt); memset(dp,-1,sizeof(dp)); while(q--){ int a,b; cin>>a>>b; ll ans = solve(a,b,0); cout<<(ans == 1e18 ? -1 : ans)<<endl; } } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t=1; //cin>>t; while(t--){ solve(); } return 0; }

Compilation message (stderr)

Main.cpp: In function 'll solve(int, int, int)':
Main.cpp:15:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   15 |     for(auto [ch,c] : adj[i]) ret = min(ret,solve(ch,j,k+1)+c);
      |              ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...