結果

問題 No.1308 ジャンプビーコン
ユーザー りあんりあん
提出日時 2020-12-04 19:14:31
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,775 bytes
コンパイル時間 2,902 ms
コンパイル使用メモリ 213,936 KB
実行使用メモリ 74,036 KB
最終ジャッジ日時 2023-10-13 09:39:56
合計ジャッジ時間 25,888 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 2 ms
4,352 KB
testcase_05 AC 1 ms
4,352 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 1 ms
4,352 KB
testcase_08 AC 2 ms
4,352 KB
testcase_09 AC 2 ms
4,352 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 1 ms
4,348 KB
testcase_12 AC 1 ms
4,352 KB
testcase_13 AC 16 ms
4,352 KB
testcase_14 AC 16 ms
4,348 KB
testcase_15 AC 17 ms
4,348 KB
testcase_16 AC 16 ms
4,352 KB
testcase_17 AC 16 ms
4,348 KB
testcase_18 AC 2,599 ms
73,976 KB
testcase_19 AC 2,679 ms
74,036 KB
testcase_20 AC 2,899 ms
73,936 KB
testcase_21 AC 2,752 ms
73,972 KB
testcase_22 AC 2,572 ms
73,836 KB
testcase_23 AC 1 ms
4,352 KB
testcase_24 AC 2 ms
4,348 KB
testcase_25 AC 2 ms
4,348 KB
testcase_26 AC 770 ms
73,916 KB
testcase_27 AC 766 ms
73,960 KB
testcase_28 AC 773 ms
73,960 KB
testcase_29 TLE -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using P = pair<long long, int>;
const long long LM = 1LL << 60;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    int n, q, c;
    cin >> n >> q >> c;
    vector<vector<P>> edge(n);
    for (int i = 0; i < n - 1; ++i) {
        int u, v, l;
        cin >> u >> v >> l;
        --u;
        --v;
        edge[u].emplace_back(l, v);
        edge[v].emplace_back(l, u);
    }
    vector<int> x(q);
    for (int i = 0; i < q; ++i) {
        cin >> x[i];
        --x[i];
    }
    vector<vector<long long>> dist(n, vector<long long>(n, LM));
    for (int i = 0; i < n; ++i) {
        queue<int> que;
        dist[i][i] = 0;
        que.push(i);
        while (!que.empty()) {
            int p = que.front();
            que.pop();
            for (auto& e : edge[p]) {
                if (dist[i][e.second] > dist[i][p] + e.first) {
                    dist[i][e.second] = dist[i][p] + e.first;
                    que.push(e.second);
                }
            }
        }
    }
    vector<long long> dp(n, LM);
    dp[x[0]] = 0;
    for (int i = 1; i < q; ++i) {
        vector<long long> nex(n, LM);
        for (int j = 0; j < n; ++j) {
            nex[j] = dp[j] + min(dist[x[i - 1]][x[i]], c + dist[j][x[i]]);
        }
        for (int k = 0; k < n; ++k) {
            if (dist[x[i - 1]][k] + dist[k][x[i]] != dist[x[i - 1]][x[i]]) continue;
            for (int j = 0; j < n; j++)
            {
                long d = min(dist[x[i - 1]][k], c + dist[j][k]) + dist[k][x[i]];
                nex[k] = min(nex[k], dp[j] + d);
            }
        }
        dp = nex;
    }
    long long ans = LM;
    for (int i = 0; i < n; ++i) {
        ans = min(ans, dp[i]);
    }
    cout << ans << '\n';

    return 0;
}
0