結果

問題 No.1690 Power Grid
ユーザー 沙耶花沙耶花
提出日時 2021-09-24 21:43:18
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 146 ms / 3,000 ms
コード長 1,023 bytes
コンパイル時間 4,322 ms
コンパイル使用メモリ 263,644 KB
実行使用メモリ 5,332 KB
最終ジャッジ日時 2023-09-18 21:02:32
合計ジャッジ時間 7,890 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 144 ms
5,200 KB
testcase_07 AC 145 ms
5,332 KB
testcase_08 AC 145 ms
5,092 KB
testcase_09 AC 144 ms
5,156 KB
testcase_10 AC 144 ms
5,268 KB
testcase_11 AC 144 ms
5,136 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 16 ms
4,376 KB
testcase_15 AC 145 ms
5,216 KB
testcase_16 AC 145 ms
5,092 KB
testcase_17 AC 68 ms
4,376 KB
testcase_18 AC 32 ms
4,376 KB
testcase_19 AC 144 ms
5,280 KB
testcase_20 AC 144 ms
5,264 KB
testcase_21 AC 146 ms
5,128 KB
testcase_22 AC 145 ms
5,204 KB
testcase_23 AC 144 ms
5,252 KB
testcase_24 AC 144 ms
5,088 KB
testcase_25 AC 144 ms
5,204 KB
testcase_26 AC 144 ms
5,092 KB
testcase_27 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 10000000000000000



int main(){
	int n,m,K;
	cin>>n>>m>>K;
	
	vector<long long> a(n);
	rep(i,n)cin>>a[i];
	
	vector<vector<long long>> dis(n,vector<long long>(n,Inf));
	rep(i,n)dis[i][i] = 0;
	
	rep(i,m){
		int x,y,z;
		cin>>x>>y>>z;
		x--;y--;
		dis[x][y] = z;
		dis[y][x] = z;
	}
	
	rep(i,n){
		rep(j,n){
			rep(k,n){
				dis[j][k] = min(dis[j][k],dis[j][i]+dis[i][k]);
			}
		}
	}
	
	vector<long long> dp(1<<n,Inf);
	rep(i,n){
		dp[1<<i] = a[i];
	}
	
	rep(i,1<<n){
		rep(j,n){
			if((i>>j)&1)continue;
			long long ni = i | (1<<j);
			long long nv = Inf;
			rep(k,n){
				if((i>>k)&1){
					nv = min(nv,dis[k][j]);
				}
			}
			nv += a[j];
			nv += dp[i];
			dp[ni] = min(dp[ni],nv);
		}
	}
	long long ans = Inf;
	rep(i,1<<n){
		if(__builtin_popcount(i)==K)ans = min(ans,dp[i]);
	}
	
	cout<<ans<<endl;
	
	return 0;
}
0