結果

問題 No.788 トラックの移動
ユーザー Shuz*Shuz*
提出日時 2019-02-08 23:49:59
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 508 ms / 2,000 ms
コード長 1,321 bytes
コンパイル時間 1,778 ms
コンパイル使用メモリ 179,564 KB
実行使用メモリ 34,528 KB
最終ジャッジ日時 2023-08-21 17:28:39
合計ジャッジ時間 5,079 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 466 ms
34,528 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 109 ms
10,940 KB
testcase_05 AC 453 ms
34,456 KB
testcase_06 AC 465 ms
34,492 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 135 ms
34,492 KB
testcase_16 AC 508 ms
34,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=a;i<b;i++)
using namespace std;
using ll=long long;
using pll=pair<ll,ll>;
template<class T>using pq=priority_queue<T,vector<T>,greater<T>>;
const ll LINF=0x1fffffffffffffff;
template<class T>bool update_min(T& a,const T& b){if(a>b){a=b;return 1;}return 0;}



signed main(){
    ll n,m,l;
    cin>>n>>m>>l;
    l--;
    vector<ll>t(n);
    rep(i,0,n)cin>>t[i];
    if(*max_element(t.begin(),t.end())==accumulate(t.begin(),t.end(),0ll))return puts("0")&0;
    vector<vector<pll>>g(n);
    rep(i,0,m){
        ll a,b,c;
        cin>>a>>b>>c;
        a--;
        b--;
        g[a].push_back({b,c});
        g[b].push_back({a,c});
    }
    vector<vector<ll>>d(n,vector<ll>(n,LINF));
    rep(i,0,n){
        vector<bool>used(n);
        pq<pll>q;
        q.push({0,i});
        d[i][i]=0;
        while(q.size()){
            ll at=q.top().second;
            q.pop();
            if(used[at])continue;
            used[at]=1;
            for(auto&j:g[at])if(update_min(d[i][j.first],d[i][at]+j.second))q.push({d[i][j.first],j.first});
        }
    }
    ll ans=LINF;
    rep(i,0,n){
        ll cnt=0;
        rep(j,0,n)cnt+=d[i][j]*t[j]*2;
        update_min(ans,cnt+d[l][i]);
        rep(j,0,n)if(t[j])update_min(ans,cnt-d[i][j]+d[l][j]);
    }
    cout<<ans<<endl;
}
0