結果

問題 No.845 最長の切符
ユーザー Yang33Yang33
提出日時 2019-07-05 16:34:14
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 827 bytes
コンパイル時間 1,613 ms
コンパイル使用メモリ 172,900 KB
実行使用メモリ 14,132 KB
最終ジャッジ日時 2023-10-21 20:13:50
合計ジャッジ時間 3,915 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define FOR(i,s,t) for(int i = s; i < t; i++)
using LL = long long;
using VL = vector<LL>;

int main() {

	int N, M; cin >> N >> M;
	const LL LINF = 1e18;
	vector<VL> cost(N, VL(N, LINF));
	FOR(i, 0, M) {
		LL a, b, c; cin >> a >> b >> c;
		a--, b--;
		cost[a][b] = cost[b][a] = min(cost[b][a], c);
	}
	vector<VL> dp(1 << N, VL(N, -LINF));
	FOR(i, 0, N) {
		dp[1 << i][i] = 0;
	}
	LL ans = 0;
	FOR(state, 0, 1 << N) {
		FOR(i, 0, N) {
			if (state & 1 << i) {
				if (dp[state][i] == -LINF)continue;
				FOR(j, 0, N) {
					if (i == j)continue;
					if (state & 1 << j)continue;
					if (cost[i][j] == LINF)continue;
					int nx = state | (1 << j);
					dp[nx][j] = max(dp[nx][j], dp[state][i] + cost[i][j]);
					ans = max(ans, dp[nx][j]);
				}
			}
		}
	}
	cout << ans << endl;
}
0