結果

問題 No.1308 ジャンプビーコン
ユーザー trineutrontrineutron
提出日時 2020-12-05 02:15:33
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,506 bytes
コンパイル時間 2,344 ms
コンパイル使用メモリ 211,336 KB
実行使用メモリ 8,816 KB
最終ジャッジ日時 2023-10-13 13:09:43
合計ジャッジ時間 13,920 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 2 ms
4,356 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 1 ms
4,352 KB
testcase_08 AC 4 ms
4,352 KB
testcase_09 AC 4 ms
4,352 KB
testcase_10 AC 4 ms
4,348 KB
testcase_11 AC 4 ms
4,348 KB
testcase_12 AC 4 ms
4,352 KB
testcase_13 AC 1,042 ms
8,524 KB
testcase_14 AC 1,029 ms
8,816 KB
testcase_15 AC 1,029 ms
8,576 KB
testcase_16 AC 1,018 ms
8,652 KB
testcase_17 AC 1,015 ms
8,560 KB
testcase_18 TLE -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
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;

template <typename T>
void chmin(T &a, T b) {
    if (b < a) {
        a = b;
    }
}

using graph = vector<vector<pair<int64_t, int64_t>>>;

void dfs(const graph &to, vector<int64_t> &dist, int v, int par) {
    for (auto [next, l] : to.at(v)) {
        if (next == par) continue;
        dist.at(next) = dist.at(v) + l;
        dfs(to, dist, next, v);
    }
}

int main() {
    constexpr int64_t inf = 1e18;
    int64_t n, q, c;
    cin >> n >> q >> c;
    graph to(n);
    for (int i = 0; i < n - 1; i++) {
        int64_t u, v, l;
        cin >> u >> v >> l;
        u--; v--;
        to.at(u).emplace_back(v, l);
        to.at(v).emplace_back(u, l);
    }
    vector<int> x(q);
    for (int i = 0; i < q; i++) {
        cin >> x.at(i);
        x.at(i)--;
    }
    vector dist(n, vector(n, int64_t()));
    for (int i = 0; i < n; i++) {
        dfs(to, dist.at(i), i, -1);
    }

    vector dp(q, vector(n, inf));
    dp.at(0).at(x.at(0)) = 0;
    for (int i = 1; i < q; i++) {
        for (int j = 0; j < n; j++) {
            for (int k = 0; k < n; k++) {
                chmin(dp.at(i).at(j), dp.at(i - 1).at(j) + dist.at(x.at(i - 1)).at(x.at(i)));
                chmin(dp.at(i).at(j), dp.at(i - 1).at(k) + dist.at(x.at(i - 1)).at(j) + dist.at(j).at(x.at(i)));
                chmin(dp.at(i).at(j), dp.at(i - 1).at(k) + c + dist.at(k).at(j) + dist.at(j).at(x.at(i)));
            }
        }
    }
    cout << dp.at(q - 1).at(x.at(q - 1)) << endl;
}
0