結果

問題 No.845 最長の切符
ユーザー SSRSSSRS
提出日時 2020-11-20 18:26:27
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 690 bytes
コンパイル時間 1,243 ms
コンパイル使用メモリ 73,824 KB
実行使用メモリ 4,508 KB
最終ジャッジ日時 2023-09-30 18:36:04
合計ジャッジ時間 2,914 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 1 ms
4,376 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 7 ms
4,380 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 8 ms
4,380 KB
testcase_29 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <utility>
using namespace std;
int main(){
	int N, M;
	cin >> N >> M;
	vector<vector<pair<int, int>>> E(N);
	for (int i = 0; i < M; i++){
		int a, b, c;
		cin >> a >> b >> c;
		a--;
		b--;
		E[a].push_back(make_pair(c, b));
		E[b].push_back(make_pair(c, a));
	}
	vector<int> dp(1 << N, 0);
	for (int i = 1; i < (1 << N); i++){
		for (int j = 0; j < N; j++){
			if (i >> j & 1){
				for (auto P : E[j]){
					int k = P.second;
					if (!(i >> k & 1)){
						dp[i | (1 << k)] = max(dp[i | (1 << k)], dp[i] + P.first);
					}
				}
			}
		}
	}
	int ans = 0;
	for (int i = 0; i < (1 << N); i++){
		ans = max(ans, dp[i]);
	}
	cout << ans << endl;
}
0