結果

問題 No.1308 ジャンプビーコン
ユーザー りあんりあん
提出日時 2020-12-02 02:05:14
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 437 ms / 4,000 ms
コード長 1,437 bytes
コンパイル時間 2,393 ms
コンパイル使用メモリ 208,704 KB
実行使用メモリ 73,856 KB
最終ジャッジ日時 2023-10-13 09:35:37
合計ジャッジ時間 9,063 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 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 2 ms
4,352 KB
testcase_06 AC 1 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,352 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 7 ms
4,352 KB
testcase_14 AC 7 ms
4,348 KB
testcase_15 AC 6 ms
4,348 KB
testcase_16 AC 6 ms
4,356 KB
testcase_17 AC 7 ms
4,352 KB
testcase_18 AC 330 ms
73,776 KB
testcase_19 AC 329 ms
73,856 KB
testcase_20 AC 332 ms
73,788 KB
testcase_21 AC 335 ms
73,852 KB
testcase_22 AC 334 ms
73,736 KB
testcase_23 AC 1 ms
4,352 KB
testcase_24 AC 2 ms
4,352 KB
testcase_25 AC 2 ms
4,348 KB
testcase_26 AC 175 ms
73,792 KB
testcase_27 AC 174 ms
73,720 KB
testcase_28 AC 175 ms
73,708 KB
testcase_29 AC 304 ms
73,740 KB
testcase_30 AC 305 ms
73,776 KB
testcase_31 AC 303 ms
73,716 KB
testcase_32 AC 354 ms
73,776 KB
testcase_33 AC 437 ms
73,856 KB
testcase_34 AC 174 ms
73,732 KB
testcase_35 AC 171 ms
73,712 KB
testcase_36 AC 195 ms
73,704 KB
testcase_37 AC 196 ms
73,708 KB
testcase_38 AC 403 ms
73,848 KB
testcase_39 AC 405 ms
73,736 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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


vector<vector<P>> edge;

void dfs(int p, int par, long long l, vector<long long>& dist) {
    dist[p] = l;
    for (auto& e : edge[p]) {
        if (e.second == par) continue;
        dfs(e.second, p, l + e.first, dist);
    }
}

long long dfs(int p, int par, long long l, long long ds, vector<long long>& dp) {
    dp[p] += min(l, ds);
    for (auto& e : edge[p]) {
        if (e.second == par) continue;
        dp[p] = min(dp[p], dfs(e.second, p, l + e.first, ds, dp));
    }
    return dp[p];
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    int n, q, c;
    cin >> n >> q >> c;
    edge = vector<vector<P>>(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<vector<long long>> dist(n, vector<long long>(n));
    for (int i = 0; i < n; ++i) {
        dfs(i, -1, 0, dist[i]);
    }
    vector<long long> dp(n, LM);
    int prev;
    cin >> prev;
    --prev;
    dp[prev] = 0;
    for (int i = 1; i < q; ++i) {
        int x;
        cin >> x;
        --x;
        dfs(x, -1, c, dist[prev][x], dp);
        prev = x;
    }
    long long ans = LM;
    for (int i = 0; i < n; ++i) {
        ans = min(ans, dp[i]);
    }
    cout << ans << '\n';
    return 0;
}
0