結果

問題 No.788 トラックの移動
ユーザー PachicobuePachicobue
提出日時 2019-02-08 22:00:07
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,270 bytes
コンパイル時間 2,387 ms
コンパイル使用メモリ 213,140 KB
実行使用メモリ 35,192 KB
最終ジャッジ日時 2023-09-14 03:40:03
合計ジャッジ時間 5,821 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 458 ms
35,192 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 99 ms
11,408 KB
testcase_05 AC 444 ms
35,104 KB
testcase_06 AC 458 ms
35,128 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 163 ms
35,180 KB
testcase_16 AC 484 ms
35,192 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using ll = long long;
template <typename T>
constexpr T MOD() { return 1000000007; }
template <typename T>
constexpr T INF() { return std::numeric_limits<T>::max() / 16; }
template <typename T>
struct CostGraph
{
    CostGraph(const std::size_t v) : V{v}, edge(v), rev_edge(v) {}
    struct Edge
    {
        Edge(const std::size_t from, const std::size_t to, const T cost) : from{from}, to{to}, cost{cost} {}
        const std::size_t from, to;
        const T cost;
        bool operator<(const Edge& e) const { return cost != e.cost ? cost < e.cost : to < e.to; }
    };
    void addEdge(const std::size_t from, const std::size_t to, const T cost) { edge[from].push_back(Edge{from, to, cost}), rev_edge[to].push_back(Edge(to, from, cost)); }
    const std::size_t V;
    std::vector<std::vector<Edge>> edge, rev_edge;
};
template <typename T>
std::vector<T> Dijkstra(const CostGraph<T>& g, const std::size_t s)
{
    std::vector<T> d(g.V, INF<T>());
    using P = std::pair<T, std::size_t>;
    std::priority_queue<P, std::vector<P>, std::greater<P>> q;
    d[s] = 0, q.push({0, s});
    while (not q.empty()) {
        const T cost = q.top().first;
        const std::size_t v = q.top().second;
        q.pop();
        if (d[v] < cost) { continue; }
        for (const auto& e : g.edge[v]) {
            if (d[e.to] <= d[v] + e.cost) { continue; }
            d[e.to] = d[v] + e.cost, q.push({d[e.to], e.to});
        }
    }
    return d;
}
int main()
{
    int N, M, L;
    std::cin >> N >> M >> L, L--;
    CostGraph<ll> g(N);
    std::vector<ll> t(N);
    for (int i = 0; i < N; i++) { std::cin >> t[i]; }
    for (int i = 0; i < M; i++) {
        int a, b;
        ll c;
        std::cin >> a >> b >> c, a--, b--;
        g.addEdge(a, b, c), g.addEdge(b, a, c);
    }
    std::vector<std::vector<ll>> d(N, std::vector<ll>(N));
    for (int i = 0; i < N; i++) { d[i] = Dijkstra(g, i); }
    ll min = INF<ll>();
    for (int i = 0; i < N; i++) {
        ll sum = 0;
        for (int j = 0; j < N; j++) { sum += 2 * t[j] * d[j][i]; }
        for (int j = 0; j < N; j++) {
            if (t[j] == 0) { continue; }
            min = std::min(min, sum - d[i][j] + d[L][j]);
        }
    }
    std::cout << min << std::endl;
    return 0;
}
0