結果

問題 No.845 最長の切符
ユーザー TlapesiumTlapesium
提出日時 2019-03-17 16:00:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 962 bytes
コンパイル時間 2,194 ms
コンパイル使用メモリ 202,504 KB
実行使用メモリ 9,924 KB
最終ジャッジ日時 2023-09-21 03:42:10
合計ジャッジ時間 4,183 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 WA -
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 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 2 ms
4,380 KB
testcase_26 AC 10 ms
9,548 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 11 ms
9,656 KB
testcase_29 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define INF 2147483647
#define INF_LL 9223372036854775807
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

vector<vector<int> > mat;
int N, M;

int main() {
	cin >> N >> M;
	mat = vector<vector<int> >(N, vector<int>(N, -1));
	for (int i = 0; i < M; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		mat[a][b] = mat[b][a] = c;
	}
	int ans = -1;

	vector<vector<int> > dp((1 << N), vector<int>(N, -1)); //dp[S][i] 集合Sに訪れていて駅iにいる
	for (int i = 0; i < N; i++)dp[1 << i][i] = 0;
	for (int i = 0; i < (1 << N); i++) {
		for (int j = 0; j < N; j++) {
			if (dp[i][j] == -1)continue;
			bool flag = false;
			for (int k = 0; k < N; k++) {
				if (i & (1 << k) || mat[j][k] == -1)continue;
				flag = true;
				dp[i + (1 << k)][k] = max(dp[i + (1 << k)][k], dp[i][j] + mat[j][k]);
			}
			if (!flag)ans = max(dp[i][j], ans);
		}

	}
	cout << ans << endl;
}
0