結果

問題 No.1690 Power Grid
ユーザー olpheolphe
提出日時 2021-09-24 21:49:18
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 138 ms / 3,000 ms
コード長 1,771 bytes
コンパイル時間 4,044 ms
コンパイル使用メモリ 132,828 KB
実行使用メモリ 5,256 KB
最終ジャッジ日時 2023-09-18 21:11:19
合計ジャッジ時間 5,356 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,384 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 138 ms
5,256 KB
testcase_07 AC 138 ms
5,144 KB
testcase_08 AC 138 ms
5,072 KB
testcase_09 AC 138 ms
5,140 KB
testcase_10 AC 138 ms
5,108 KB
testcase_11 AC 137 ms
5,084 KB
testcase_12 AC 1 ms
4,384 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 15 ms
4,384 KB
testcase_15 AC 137 ms
5,076 KB
testcase_16 AC 137 ms
5,076 KB
testcase_17 AC 65 ms
4,384 KB
testcase_18 AC 31 ms
4,384 KB
testcase_19 AC 138 ms
5,256 KB
testcase_20 AC 138 ms
5,076 KB
testcase_21 AC 138 ms
5,072 KB
testcase_22 AC 138 ms
5,192 KB
testcase_23 AC 138 ms
5,144 KB
testcase_24 AC 138 ms
5,144 KB
testcase_25 AC 138 ms
5,244 KB
testcase_26 AC 137 ms
5,144 KB
testcase_27 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

//constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-8;

//int N, M, K, T, H, W, L, R;
long long int N, M, K, T, H, W, L, R;


int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);

	cin >> N;
	vector<vector<long long>>edge(N, vector<long long>(N, 1LL << 44));
	for (int i = 0; i < N; i++) {
		edge[i][i] = 0;
	}
	cin >> M >> K;
	vector<long long>cost(N);
	for (auto& i : cost)cin >> i;
	for (int i = 0; i < M; i++) {
		cin >> L >> R >> H;
		L--, R--;
		edge[L][R] = H;
		edge[R][L] = H;
	}
	for (int k = 0; k < N; k++) {
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < N; j++) {
				edge[i][j] = min(edge[i][j], edge[i][k] + edge[k][j]);
			}
		}
	}
	vector<long long>dp(1 << N, 1LL << 44);
	dp[0] = 0;
	for (int i = 0; i < 1 << N; i++) {
		for (int j = 0; j < N; j++) {
			if (i >> j & 1)continue;
			long long add = 1LL << 44;
			if (i == 0)add = 0;
			for (int k = 0; k < N; k++) {
				if (i >> k & 1) {
					add = min(add, edge[j][k]);
				}
			}
			dp[i | (1 << j)] = min(dp[i | (1 << j)], dp[i] + add + cost[j]);
		}
	}
	long long ans = 1LL << 55;
	for (int i = 0; i <1<< N; i++) {
		int num = 0;
		for (int j = 0; j < N; j++) {
			if (i >> j & 1)num++;
		}
		if (num == K) {
			ans = min(ans, dp[i]);
		}
	}
	cout << ans << endl;
}
0