結果

問題 No.845 最長の切符
ユーザー finefine
提出日時 2019-06-28 22:19:31
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,148 bytes
コンパイル時間 1,586 ms
コンパイル使用メモリ 170,072 KB
実行使用メモリ 103,308 KB
最終ジャッジ日時 2023-09-14 22:08:29
合計ジャッジ時間 11,589 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,568 KB
testcase_01 AC 3 ms
9,704 KB
testcase_02 AC 4 ms
12,180 KB
testcase_03 AC 2 ms
5,684 KB
testcase_04 AC 3 ms
7,504 KB
testcase_05 WA -
testcase_06 AC 3 ms
7,620 KB
testcase_07 AC 3 ms
7,584 KB
testcase_08 AC 5 ms
12,228 KB
testcase_09 AC 3 ms
9,732 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 5 ms
12,588 KB
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 18 ms
17,708 KB
testcase_27 AC 3 ms
5,464 KB
testcase_28 AC 19 ms
6,680 KB
testcase_29 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using P = pair<int, ll>;

ll dp[16][16][1 << 16];
bool memo[16][16][1 << 16];
vector<P> g[16];

void dfs(int src, int cur, int used) {
    memo[src][cur][used] = true;
    for (P& p : g[cur]) {
        if (used & (1 << p.first)) continue;
        int n_used = (used | (1 << p.first));
        ll& tar = dp[src][p.first][n_used];
        ll cost = dp[src][cur][used] + p.second;
        if (tar < cost) {
            tar = cost;
            if (!memo[src][p.first][n_used]) dfs(src, p.first, n_used);
        }
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int a, b;
        ll c;
        cin >> a >> b >> c;
        a--; b--;
        g[a].emplace_back(b, c);
        g[b].emplace_back(a, c);
    }

    ll ans = 0;
    for (int i = 0; i < n; i++) {
        dfs(i, i, 1 << i);
        for (int j = 0; j < n; j++) {
            for (int k = 0; k < (1 << n); k++) {
                ans = max(ans, dp[i][j][k]);
            }
        }
    }
    cout << ans << endl;
    return 0;
}
0