Submission #975902

#TimeUsernameProblemLanguageResultExecution timeMemory
975902NipphitchCities (BOI16_cities)C++14
100 / 100
1676 ms49516 KiB
#include <bits/stdc++.h> #pragma GCC optimize ("O3,unroll-loops") #pragma GCC target ("avx2,bmi,bmi2,lzcnt,popcnt") using namespace std; #define ll long long #define pii pair <ll,int> const int N=1e5+5; const int K=40; const ll INF=LLONG_MAX/2; int n,k,m; ll dp[K][N]; vector <pii> adj[N]; priority_queue <pii,vector<pii>,greater<pii>> pq; int main() { ios::sync_with_stdio(0); cin.tie(0); fill_n(dp[0],K*N,INF); cin >> n >> k >> m; for(int i=0;i<k;i++){ int x; cin >> x; dp[(1<<i)][x]=0; } for(int i=0;i<m;i++){ int u,v,w; cin >> u >> v >> w; adj[u].push_back({v,w}); adj[v].push_back({u,w}); } for(int mask1=1;mask1<(1<<k);mask1++){ for(int mask2=1;mask2<mask1;mask2++) if(mask1&mask2) for(int i=1;i<=n;i++) dp[mask1][i]=min(dp[mask1][i],dp[mask2][i]+dp[mask1^mask2][i]); for(int i=1;i<=n;i++) if(dp[mask1][i]!=INF) pq.push({dp[mask1][i],i}); while(!pq.empty()){ auto [d_u,u]=pq.top(); pq.pop(); for(auto [v,w]:adj[u]) if(dp[mask1][v]>d_u+w) pq.push({dp[mask1][v]=d_u+w,v}); } } cout << *min_element(dp[(1<<k)-1]+1,dp[(1<<k)-1]+1+n); }

Compilation message (stderr)

cities.cpp: In function 'int main()':
cities.cpp:37:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   37 |             auto [d_u,u]=pq.top();
      |                  ^
cities.cpp:39:22: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   39 |             for(auto [v,w]:adj[u]) if(dp[mask1][v]>d_u+w) pq.push({dp[mask1][v]=d_u+w,v});
      |                      ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...