Submission #872665

#TimeUsernameProblemLanguageResultExecution timeMemory
872665HossamHero7Autobus (COCI22_autobus)C++14
55 / 70
1087 ms756 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define endl '\n' int edge[75][75]; vector<pair<int,ll>> adj[75]; ll dp[75][75][2]; 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 k,q; cin>>k>>q; k = min(k,cnt); for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) dp[i][j][0] = (i == j ? 0 : 1e18); for(int rem=1;rem<=k;rem++){ for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ dp[i][j][rem&1] = dp[i][j][rem-1&1]; for(auto [ch,c] : adj[i]) dp[i][j][rem&1] = min(dp[ch][j][rem-1&1] + c,dp[i][j][rem&1]); } } } while(q--){ int a,b; cin>>a>>b; cout<<(dp[a][b][k&1] == 1e18 ? -1 : dp[a][b][k&1])<<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 'void solve()':
Main.cpp:30:47: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   30 |                 dp[i][j][rem&1] = dp[i][j][rem-1&1];
      |                                            ~~~^~
Main.cpp:31:26: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   31 |                 for(auto [ch,c] : adj[i]) dp[i][j][rem&1] = min(dp[ch][j][rem-1&1] + c,dp[i][j][rem&1]);
      |                          ^
Main.cpp:31:78: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   31 |                 for(auto [ch,c] : adj[i]) dp[i][j][rem&1] = min(dp[ch][j][rem-1&1] + c,dp[i][j][rem&1]);
      |                                                                           ~~~^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...