結果

問題 No.788 トラックの移動
ユーザー rpy3cpprpy3cpp
提出日時 2019-05-05 00:36:41
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,820 bytes
コンパイル時間 1,880 ms
コンパイル使用メモリ 181,244 KB
実行使用メモリ 34,684 KB
最終ジャッジ日時 2023-09-05 18:02:46
合計ジャッジ時間 5,156 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 468 ms
34,512 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 103 ms
10,928 KB
testcase_05 AC 458 ms
34,684 KB
testcase_06 AC 468 ms
34,508 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 153 ms
34,504 KB
testcase_16 AC 498 ms
34,512 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
constexpr long long INF = 1e18;

struct Edge{
    int to;
    long long cost;
    Edge(int to, long long cost):to(to), cost(cost) {}
};

void dijkstra(int start, vector<long long> &dist, const vector<vector<Edge>> &Es){
    int N = Es.size();
    dist.assign(N, INF);
    dist[start] = 0;
    priority_queue<pair<long long, int>, vector<pair<long long, int>>, greater<pair<long long, int>>> pq;
    pq.push(make_pair(0LL, start));
    while (not pq.empty()){
        auto dv = pq.top();
        pq.pop();
        if (dv.first > dist[dv.second]) continue;
        dist[dv.second] = dv.first;
        for (auto &uc : Es[dv.second]){
            long long new_d = dv.first + uc.cost;
            if (new_d < dist[uc.to]){
                dist[uc.to] = new_d;
                pq.push(make_pair(new_d, uc.to));
            }
        }
    }
}


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M, L;
    cin >> N >> M >> L;
    vector<int> Ts(N, 0);
    for (auto & t : Ts) cin >> t;
    vector<vector<Edge>> Es(N, vector<Edge>());
    for (int i = 0; i < M; ++i){
        int a, b;
        long long c;
        cin >> a >> b >> c;
        Es[a - 1].push_back({b - 1, c});
        Es[b - 1].push_back({a - 1, c});
    }
    vector<vector<long long>> dist(N, vector<long long>());
    for (int v = 0; v < N; ++v) dijkstra(v, dist[v], Es);
    long long ans = INF;
    for (int g = 0; g < N; ++g){
        long long len = 0LL;
        for (int i = 0; i < N; ++i) len += dist[g][i] * 2 * Ts[i];
        long long dif = INF;
        for (int j = 0; j < N; ++j) {
            if (Ts[j] >= 1){
                dif = min(dif, dist[L - 1][j] - dist[j][g]);
            }
        }
        ans = min(ans, len + dif);
    }
    cout << ans << endl;
    return 0;
}

0