Submission #926559

#TimeUsernameProblemLanguageResultExecution timeMemory
926559irmuunCities (BOI16_cities)C++17
100 / 100
2892 ms51904 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define ff first #define ss second #define all(s) s.begin(),s.end() #define rall(s) s.rbegin(),s.rend() int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n,k,m; cin>>n>>k>>m; ll dp[32][n]; int p[k]; vector<pair<int,ll>>adj[n]; for(int i=0;i<k;i++){ cin>>p[i]; p[i]--; } for(int i=0;i<m;i++){ int a,b; ll c; cin>>a>>b>>c; a--,b--; adj[a].pb({b,c}); adj[b].pb({a,c}); } for(int i=0;i<(1<<k);i++){ for(int j=0;j<n;j++){ dp[i][j]=1e18; } } for(int i=0;i<k;i++){ dp[1<<i][p[i]]=0; } for(int c=0;c<(1<<k);c++){ for(int a=0;a<c;a++){ if((a|c)!=c) continue; int b=a^c; if(b>a) continue; for(int i=0;i<n;i++){ dp[c][i]=min(dp[c][i],dp[a][i]+dp[b][i]); } } set<pair<ll,int>>st; vector<bool>used(n,0); for(int i=0;i<n;i++){ if(dp[c][i]<1e18){ st.insert({dp[c][i],i}); } } while(!st.empty()){ auto [d,i]=*st.begin(); st.erase(st.begin()); if(used[i]==true) continue; used[i]=true; for(auto [j,C]:adj[i]){ ll cost=C+d; if(cost<dp[c][j]){ dp[c][j]=cost; st.insert({dp[c][j],j}); } } } } ll ans=1e18; for(int i=0;i<n;i++){ ans=min(ans,dp[(1<<k)-1][i]); } cout<<ans; }
#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...