Submission #956242

#TimeUsernameProblemLanguageResultExecution timeMemory
95624212345678Cities (BOI16_cities)C++17
100 / 100
2035 ms49872 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long const int nx=1e5+5; ll n, m, k, x, dp[33][nx], u, v, w, res=LLONG_MAX; vector<pair<ll, ll>> d[nx]; int main() { cin.tie(NULL)->sync_with_stdio(false); cin>>n>>k>>m; for (int i=1; i<(1<<k); i++) for (int j=1; j<=n; j++) dp[i][j]=1e18; for (int i=0; i<k; i++) cin>>x, dp[(1<<i)][x]=0; for (int i=0; i<m; i++) cin>>u>>v>>w, d[u].push_back({v, w}), d[v].push_back({u, w}); for (int i=1; i<(1<<k); i++) { for (int j=1; j<=n; j++) for (int k=i; k>0; k=(k-1)&i) dp[i][j]=min(dp[i][j], dp[i^k][j]+dp[k][j]); priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> pq; for (int j=1; j<=n; j++) pq.push({dp[i][j], j}); while (!pq.empty()) { auto [w, u]=pq.top(); pq.pop(); for (auto [v, nw]:d[u]) if (w+nw<dp[i][v]) dp[i][v]=w+nw, pq.push({w+nw, v}); } } for (int i=1; i<=n; i++) res=min(res, dp[(1<<k)-1][i]); cout<<res; }
#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...