結果

問題 No.845 最長の切符
ユーザー Yang33Yang33
提出日時 2019-07-05 16:42:08
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 62 ms / 3,000 ms
コード長 829 bytes
コンパイル時間 1,649 ms
コンパイル使用メモリ 172,484 KB
実行使用メモリ 14,132 KB
最終ジャッジ日時 2023-10-21 20:19:44
合計ジャッジ時間 3,023 ms
ジャッジサーバーID
(参考情報)
judge10 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 3 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 3 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 14 ms
5,708 KB
testcase_16 AC 58 ms
14,132 KB
testcase_17 AC 14 ms
5,708 KB
testcase_18 AC 28 ms
8,060 KB
testcase_19 AC 7 ms
4,556 KB
testcase_20 AC 61 ms
14,132 KB
testcase_21 AC 62 ms
14,132 KB
testcase_22 AC 14 ms
5,708 KB
testcase_23 AC 4 ms
4,348 KB
testcase_24 AC 59 ms
14,132 KB
testcase_25 AC 2 ms
4,348 KB
testcase_26 AC 18 ms
14,132 KB
testcase_27 AC 2 ms
4,348 KB
testcase_28 AC 18 ms
14,132 KB
testcase_29 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

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] = max(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