結果

問題 No.1690 Power Grid
ユーザー たたき@競プロたたき@競プロ
提出日時 2023-08-27 13:28:11
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 159 ms / 3,000 ms
コード長 928 bytes
コンパイル時間 5,711 ms
コンパイル使用メモリ 309,760 KB
実行使用メモリ 5,332 KB
最終ジャッジ日時 2023-08-27 13:28:21
合計ジャッジ時間 9,134 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 158 ms
5,204 KB
testcase_07 AC 159 ms
5,180 KB
testcase_08 AC 156 ms
5,132 KB
testcase_09 AC 158 ms
5,204 KB
testcase_10 AC 158 ms
5,300 KB
testcase_11 AC 158 ms
5,256 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 17 ms
4,380 KB
testcase_15 AC 158 ms
5,332 KB
testcase_16 AC 158 ms
5,328 KB
testcase_17 AC 74 ms
4,376 KB
testcase_18 AC 36 ms
4,376 KB
testcase_19 AC 158 ms
5,204 KB
testcase_20 AC 158 ms
5,228 KB
testcase_21 AC 158 ms
5,296 KB
testcase_22 AC 158 ms
5,152 KB
testcase_23 AC 158 ms
5,328 KB
testcase_24 AC 157 ms
5,252 KB
testcase_25 AC 157 ms
5,208 KB
testcase_26 AC 159 ms
5,164 KB
testcase_27 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
    
0