結果
問題 |
No.1690 Power Grid
|
ユーザー |
![]() |
提出日時 | 2023-08-27 13:28:11 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 170 ms / 3,000 ms |
コード長 | 928 bytes |
コンパイル時間 | 7,153 ms |
コンパイル使用メモリ | 310,592 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-12-27 10:05:29 |
合計ジャッジ時間 | 9,196 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 25 |
ソースコード
#include<bits/stdc++.h> using namespace std; #include <atcoder/all> using namespace atcoder; using mint=modint998244353; //1000000007; using ll=long long; using pp=pair<int,int>; #define sr string #define vc vector #define fi first #define se second #define rep(i,n) for(int i=0;i<(int)n;i++) #define pb push_back #define all(v) v.begin(),v.end() #define pque priority_queue #define bpc(a) __builtin_popcount(a) int main(){ int n,m,kk;cin>>n>>m>>kk; vc d(n,vc<ll>(n,1e18)); vc<ll>x(n); rep(i,n)cin>>x[i]; rep(i,m){ int a,b,c;cin>>a>>b>>c; a--;b--; d[a][b]=c; d[b][a]=c; } rep(i,n)rep(j,n)rep(k,n)d[j][k]=min(d[j][k],d[j][i]+d[i][k]); vc<ll>dp(1<<n,1e18); rep(i,n)dp[1<<i]=x[i]; rep(i,1<<n)rep(j,n)if(~i>>j&1){ ll mn=1e18; rep(k,n)if(k!=j&&i>>k&1)mn=min(mn,d[j][k]); dp[i|1<<j]=min(dp[i|1<<j],dp[i]+x[j]+mn); } ll ans=1e18; rep(i,1<<n)if(bpc(i)==kk)ans=min(ans,dp[i]); cout<<ans; }