結果

問題 No.845 最長の切符
ユーザー finefine
提出日時 2019-06-28 22:16:01
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,050 bytes
コンパイル時間 1,663 ms
コンパイル使用メモリ 169,128 KB
実行使用メモリ 8,296 KB
最終ジャッジ日時 2023-09-14 22:06:53
合計ジャッジ時間 7,743 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
8,056 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 3 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 880 ms
5,340 KB
testcase_11 AC 159 ms
4,376 KB
testcase_12 AC 21 ms
4,428 KB
testcase_13 AC 4 ms
4,376 KB
testcase_14 AC 3 ms
4,380 KB
testcase_15 TLE -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

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

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

void dfs(int src, int cur, int used) {
    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;
        }
        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