結果

問題 No.845 最長の切符
ユーザー finefine
提出日時 2019-06-28 22:37:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,316 bytes
コンパイル時間 1,720 ms
コンパイル使用メモリ 178,736 KB
実行使用メモリ 44,756 KB
最終ジャッジ日時 2023-09-14 22:21:24
合計ジャッジ時間 7,440 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
16,296 KB
testcase_01 AC 4 ms
15,640 KB
testcase_02 AC 6 ms
22,136 KB
testcase_03 AC 3 ms
9,640 KB
testcase_04 AC 4 ms
13,648 KB
testcase_05 AC 3 ms
11,812 KB
testcase_06 AC 4 ms
11,576 KB
testcase_07 AC 3 ms
11,632 KB
testcase_08 AC 6 ms
20,160 KB
testcase_09 AC 5 ms
15,736 KB
testcase_10 AC 20 ms
25,324 KB
testcase_11 AC 6 ms
17,920 KB
testcase_12 AC 9 ms
22,600 KB
testcase_13 AC 6 ms
18,012 KB
testcase_14 AC 7 ms
22,444 KB
testcase_15 AC 657 ms
44,756 KB
testcase_16 TLE -
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>;
using T = tuple<ll, int, int>;

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

void dfs(int src, ll& ans) {
    priority_queue<T> pq;
    pq.emplace(0, src, 1 << src);
    dp[src][src][1 << src] = -1;
    while (!pq.empty()) {
        ll c, cur, used;
        tie(c, cur, used) = pq.top();
        pq.pop();
        //if (dp[src][cur][used] >= c) continue;
        dp[src][cur][used] = c;

        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;
                ans = max(ans, tar);
                pq.emplace(cost, 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, ans);
    }
    cout << ans << endl;
    return 0;
}
0