結果

問題 No.845 最長の切符
ユーザー leaf_1415leaf_1415
提出日時 2019-07-01 22:25:13
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 38 ms / 3,000 ms
コード長 978 bytes
コンパイル時間 510 ms
コンパイル使用メモリ 59,788 KB
実行使用メモリ 11,724 KB
最終ジャッジ日時 2023-09-25 09:38:58
合計ジャッジ時間 2,718 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <utility>
#define llint long long
#define inf 1e18

using namespace std;
typedef pair<llint, llint> P;

llint n, m;
llint G[20][20];
llint dp[1<<16][16];

int main(void)
{
	cin >> n >> m;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			G[i][j] = -inf;
		}
	}
	llint u, v, w;
	for(int i = 1; i <= m; i++){
		cin >> u >> v >> w;
		u--, v--;
		G[u][v] = max(G[u][v], w);
		G[v][u] = max(G[v][u], w);
	}
	
	int N = 1<<n;
	for(int i = 0; i < N; i++){
		for(int j = 0; j < n; j++){
			dp[i][j] = -1e18;
		}
	}
	for(int i = 0; i < n; i++) dp[1<<i][i] = 0;
	for(int i = 0; i < N; i++){
		for(int j = 0; j < n; j++){
			for(int k = 0; k < n; k++){
				if(i & (1 << k)) continue;
				dp[i | (1<<k)][k] = max(dp[i | (1<<k)][k], dp[i][j] + G[j][k]);
			}
		}
	}
	
	llint ans = 0;
	for(int i = 0; i < N; i++){
		for(int j = 0; j < n; j++){
			ans = max(ans, dp[i][j]);
		}
	}
	cout << ans << endl;
	
	return 0;
}
0