結果

問題 No.845 最長の切符
ユーザー ikdikd
提出日時 2019-06-28 22:43:10
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 959 bytes
コンパイル時間 677 ms
コンパイル使用メモリ 74,124 KB
実行使用メモリ 9,932 KB
最終ジャッジ日時 2023-09-14 22:26:08
合計ジャッジ時間 2,288 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

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

void chmin(int &a, int b) {
  if (a > b) a = b;
}

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, inf));
  rep(i, n) d[i][i] = 0;
  rep(i, m) {
    int a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    chmin(d[a][b], c);
    chmin(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] < inf) {
            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