Submission #647555

#TimeUsernameProblemLanguageResultExecution timeMemory
647555ToroTNCities (BOI16_cities)C++14
14 / 100
6095 ms43820 KiB
#include<bits/stdc++.h> using namespace std; #define pb push_back #define ll long long #define X first #define Y second ll n,k,m,node[5],u_i,v_i,w_i,d[32][100005],u,num,dp[32],pow_2[5],mn=1e18; vector<pair<ll,ll> > g[100005]; vector<ll> bit[6]; priority_queue<pair<ll,ll> > pq; void dij(ll arr[]) { for(int i=1;i<=n;i++) { pq.push({-arr[i],i}); } while(!pq.empty()) { u=pq.top().second; pq.pop(); for(auto [y,cost]:g[u]) { if(arr[u]+cost<arr[y]) { arr[y]=arr[u]+cost; pq.push({-arr[y],y}); } } } } int main() { pow_2[0]=1; for(int i=1;i<=4;i++) { pow_2[i]=pow_2[i-1]*2; } scanf("%lld%lld%lld",&n,&num,&m); for(int i=1;i<=num;i++) { scanf("%lld",&node[i-1]); } for(int i=1;i<=m;i++) { scanf("%lld%lld%lld",&u_i,&v_i,&w_i); g[u_i].pb({v_i,w_i}); g[v_i].pb({u_i,w_i}); } for(int i=0;i<32;i++) { for(int j=1;j<=n;j++) { d[i][j]=1e18; } } for(int i=0;i<num;i++) { d[pow_2[i]][node[i]]=0; dij(d[pow_2[i]]); } for(int i=0;i<32;i++) { ll kmp=0; for(int j=0;j<=4;j++) { if((i|pow_2[j])==i)++kmp; } bit[kmp].pb(i); } // for(int i=1;i<=n;i++) // { // printf("%lld ",d[1][i]); // } // printf("\n"); for(int i=2;i<=num;i++) { for(int j=1;j<=i/2;j++) { for(auto k:bit[i-j]) { for(auto l:bit[j]) { if(k!=l) { for(int c=1;c<=n;c++) { d[(k|l)][c]=d[k][c]+d[l][c]; } dij(d[(k|l)]); } } } } } for(int i=1;i<=n;i++) { mn=min(mn,d[pow_2[num]-1][i]); } printf("%lld\n",mn); }

Compilation message (stderr)

cities.cpp: In function 'void dij(long long int*)':
cities.cpp:21:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   21 |         for(auto [y,cost]:g[u])
      |                  ^
cities.cpp: In function 'int main()':
cities.cpp:38:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |     scanf("%lld%lld%lld",&n,&num,&m);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
cities.cpp:41:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |         scanf("%lld",&node[i-1]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~
cities.cpp:45:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |         scanf("%lld%lld%lld",&u_i,&v_i,&w_i);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...