結果

問題 No.1690 Power Grid
ユーザー tko919tko919
提出日時 2021-09-25 04:37:36
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 129 ms / 3,000 ms
コード長 1,183 bytes
コンパイル時間 2,173 ms
コンパイル使用メモリ 200,900 KB
実行使用メモリ 5,516 KB
最終ジャッジ日時 2023-09-18 22:48:41
合計ジャッジ時間 5,328 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,384 KB
testcase_06 AC 124 ms
5,468 KB
testcase_07 AC 127 ms
5,400 KB
testcase_08 AC 124 ms
5,396 KB
testcase_09 AC 125 ms
5,384 KB
testcase_10 AC 124 ms
5,508 KB
testcase_11 AC 124 ms
5,456 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 14 ms
4,384 KB
testcase_15 AC 126 ms
5,372 KB
testcase_16 AC 127 ms
5,448 KB
testcase_17 AC 60 ms
4,664 KB
testcase_18 AC 29 ms
4,384 KB
testcase_19 AC 126 ms
5,460 KB
testcase_20 AC 126 ms
5,456 KB
testcase_21 AC 128 ms
5,372 KB
testcase_22 AC 126 ms
5,404 KB
testcase_23 AC 125 ms
5,448 KB
testcase_24 AC 125 ms
5,376 KB
testcase_25 AC 127 ms
5,380 KB
testcase_26 AC 129 ms
5,516 KB
testcase_27 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define ALL(v) (v).begin(),(v).end()
using ll=long long int;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
template<typename T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}

ll dp[1<<18];

int main(){
   int n,m,k;
   cin>>n>>m>>k;
   vector<ll> a(n);
   rep(i,0,n)cin>>a[i];
   ll d[20][20];
   rep(i,0,n)rep(j,0,n)d[i][j]=INF;
   rep(i,0,n)d[i][i]=0;
   rep(_,0,m){
      int u,v,w;
      cin>>u>>v>>w;
      u--; v--;
      d[u][v]=d[v][u]=w;
   }
   
   rep(k,0,n)rep(i,0,n)rep(j,0,n)chmin(d[i][j],d[i][k]+d[k][j]);
   rep(mask,0,1<<n)dp[mask]=INF;
   dp[0]=0;
   rep(mask,0,1<<n){
      rep(to,0,n)if(!(mask>>to&1)){
         ll add=INF;
         rep(from,0,n)if(mask>>from&1){
            chmin(add,d[from][to]);
         }
         if(mask==0)add=0;
         chmin(dp[mask|(1<<to)],dp[mask]+add+a[to]);
      }
   }
   ll res=INF;
   rep(mask,0,1<<n)if(__builtin_popcountll(mask)==k)chmin(res,dp[mask]);
   cout<<res<<'\n';
   return 0;
}
0