結果

問題 No.845 最長の切符
ユーザー ikdikd
提出日時 2019-06-28 22:45:55
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 69 ms / 3,000 ms
コード長 906 bytes
コンパイル時間 750 ms
コンパイル使用メモリ 74,500 KB
実行使用メモリ 9,888 KB
最終ジャッジ日時 2023-09-14 22:27:32
合計ジャッジ時間 2,294 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 3 ms
4,376 KB
testcase_11 AC 2 ms
4,384 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 14 ms
4,384 KB
testcase_16 AC 55 ms
9,576 KB
testcase_17 AC 13 ms
4,484 KB
testcase_18 AC 27 ms
6,508 KB
testcase_19 AC 7 ms
4,380 KB
testcase_20 AC 62 ms
9,580 KB
testcase_21 AC 69 ms
9,628 KB
testcase_22 AC 14 ms
4,544 KB
testcase_23 AC 5 ms
4,380 KB
testcase_24 AC 55 ms
9,888 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 41 ms
9,696 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 50 ms
9,776 KB
testcase_29 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

void chmax(int &a, int b) {
  if (a < b) a = b;
}

int main() {

  int n, m;
  cin >> n >> m;
  const int inf = 1000000000;
  vector<vector<int>> d(n, vector<int>(n, -1));
  rep(i, n) d[i][i] = 0;
  rep(i, m) {
    int a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    chmax(d[a][b], c);
    chmax(d[b][a], c);
  }

  vector<vector<int>> dp(1 << n, vector<int>(n, 0));
  rep(bits, 1 << n) {
    rep(v, n) {
      if (bits >> v & 1) {
        rep(w, n) {
          if (!(bits >> w & 1) and d[v][w] >= 0) {
            chmax(dp[bits ^ (1 << w)][w], dp[bits][v] + d[v][w]);
          }
        }
      }
    }
  }
  int ans = 0;
  rep(bits, 1 << n) {
    rep(v, n) {
      if (bits >> v & 1) { chmax(ans, dp[bits][v]); }
    }
  }
  cout << ans << endl;

  return 0;
}
0