結果

問題 No.788 トラックの移動
ユーザー hiro71687khiro71687k
提出日時 2023-08-03 13:09:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 426 ms / 2,000 ms
コード長 2,362 bytes
コンパイル時間 4,421 ms
コンパイル使用メモリ 260,936 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 11:11:33
合計ジャッジ時間 7,151 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 384 ms
5,248 KB
testcase_01 AC 1 ms
5,248 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 88 ms
5,376 KB
testcase_05 AC 371 ms
5,376 KB
testcase_06 AC 375 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 96 ms
5,376 KB
testcase_16 AC 426 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using namespace std;
using ll=long long;
using ld=long double;
ld pie=3.141592653589793;
ll mod=1000000007;
ll inf=10099999999999990;
int main(){
    ll n,m,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>>>g(n);
    for (ll i = 0; i < m; i++)
    {
        ll a,b,c;
        cin >> a >> b >> c;
        a--,b--;
        g[a].push_back({b,c});
        g[b].push_back({a,c});
    }
    ll ans=inf;
    vector<ll>mm;
    vector<ll>memo(n,inf);
    memo[l]=0;
    priority_queue<pair<ll,ll>,vector<pair<ll,ll>>,greater<pair<ll,ll>>>pq;
    pq.push({0,l});
    while (!pq.empty())
    {
        ll v=pq.top().second;
        ll x=pq.top().first;
        pq.pop();
        if (x!=memo[v])
        {
            continue;
        }
            
        for (ll j = 0; j < g[v].size(); j++)
        {
            if (memo[g[v][j].first]>memo[v]+g[v][j].second)
            {
                if (1)
                {
                    pq.push({memo[v]+g[v][j].second,g[v][j].first});
                }
                memo[g[v][j].first]=memo[v]+g[v][j].second;
            }
        }
    }
    mm=memo;
    for (ll i = 0; i < n; i++)
    {
        vector<ll>memo(n,inf);
        memo[i]=0;
        priority_queue<pair<ll,ll>,vector<pair<ll,ll>>,greater<pair<ll,ll>>>pq;
        pq.push({0,i});
        while (!pq.empty())
        {
            ll v=pq.top().second;
            ll x=pq.top().first;
            pq.pop();
            if (x!=memo[v])
            {
                continue;
            }
            
            for (ll j = 0; j < g[v].size(); j++)
            {
                if (memo[g[v][j].first]>memo[v]+g[v][j].second)
                {
                    if (1)
                    {
                        pq.push({memo[v]+g[v][j].second,g[v][j].first});
                    }
                    memo[g[v][j].first]=memo[v]+g[v][j].second;
                }
            }
        }
        ll x=0;
        ll z=0;
        for (ll j = 0; j < n; j++)
        {
            x+=memo[j]*t[j]*2;
            if (t[j]>=1)
            {
                z=max(z,memo[j]-mm[j]);
            }
        }
        x-=z;
        ans=min(ans,x);
    }
    cout << ans << endl;
}
0