結果

問題 No.845 最長の切符
ユーザー 0w10w1
提出日時 2019-08-01 23:12:47
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 333 ms / 3,000 ms
コード長 822 bytes
コンパイル時間 2,652 ms
コンパイル使用メモリ 208,528 KB
実行使用メモリ 9,692 KB
最終ジャッジ日時 2023-09-18 18:06:25
合計ジャッジ時間 4,841 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 3 ms
4,380 KB
testcase_11 AC 2 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,380 KB
testcase_15 AC 16 ms
4,408 KB
testcase_16 AC 333 ms
9,572 KB
testcase_17 AC 82 ms
4,552 KB
testcase_18 AC 54 ms
6,436 KB
testcase_19 AC 15 ms
4,380 KB
testcase_20 AC 79 ms
9,648 KB
testcase_21 AC 47 ms
9,692 KB
testcase_22 AC 70 ms
4,504 KB
testcase_23 AC 15 ms
4,376 KB
testcase_24 AC 276 ms
9,680 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 15 ms
9,552 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 16 ms
9,608 KB
testcase_29 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
  ios::sync_with_stdio(false);

  int N, M;
  cin >> N >> M;

  vector<vector<pair<int, int>>> G(N);
  for (int i = 0; i < M; ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    G[a - 1].emplace_back(c, b - 1);
    G[b - 1].emplace_back(c, a - 1);
  }

  vector<vector<int>> dp(1 << N, vector<int>(N));
  for (int s = 0; s < 1 << N; ++s) {
    for (int x = 0; x < N; ++x) {
      if (~s >> x & 1) continue;
      for (auto e : G[x]) {
        int w, y;
        tie(w, y) = e;
        if (s >> y & 1) continue;
        dp[s | 1 << y][y] = max(dp[s | 1 << y][y], dp[s][x] + w);
      }
    }
  }

  int ans = 0;
  for (int s = 0; s < 1 << N; ++s) {
    for (int i = 0; i < N; ++i) {
      ans = max(ans, dp[s][i]);
    }
  }

  cout << ans << endl;

  return 0;
}
0