結果

問題 No.788 トラックの移動
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2024-02-09 17:57:05
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,378 bytes
コンパイル時間 2,747 ms
コンパイル使用メモリ 216,080 KB
実行使用メモリ 34,816 KB
最終ジャッジ日時 2024-02-09 17:57:12
合計ジャッジ時間 5,617 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 406 ms
34,816 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 1 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 92 ms
11,264 KB
testcase_05 AC 391 ms
34,816 KB
testcase_06 AC 387 ms
34,816 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 AC 1 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 2 ms
6,676 KB
testcase_12 AC 1 ms
6,676 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 131 ms
34,816 KB
testcase_16 AC 417 ms
34,816 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    ll n, m, x, y, z, l;
    cin >> n >> m >> l;
    l--;
    vector<ll> t(n);
    for (ll i = 0; i < n; i++) {
        cin >> t[i];
    }
    vector<vector<pair<ll, ll>>> e(n);
    for (int i=0; i<m; i++){
        cin >> x >> y >> z; x--; y--;
        e[x].push_back({y, z});
        e[y].push_back({x, z});
    }

    vector dist(n, vector<ll>(n, 1e18));
    for (int i=0; i<n; i++){
        priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> que;
        que.push({0, i});
        dist[i][i] = 0;
        while(!que.empty()){
            tie(z, x) = que.top();
            que.pop();
            if (dist[i][x] < z) continue;
            for (auto [y, w] : e[x]){
                if (dist[i][y] > dist[i][x] + w){
                    dist[i][y] = dist[i][x] + w;
                    que.push({dist[i][y], y});
                }
            }
        }
    }

    ll ans = 1e18;
    for (int i=0; i<n; i++){
        ll sm = 0;
        for (int j=0; j<n; j++){
            sm += t[j] * dist[i][j] * 2;
        }
        ans = min(ans, sm+dist[i][l]);
        for (int j=0; j<n; j++){
            if (t[j] > 0) ans = min(ans, sm+dist[l][j]-dist[i][j]);
        }
    }

    cout << ans << endl;

    return 0;
}
0