結果

問題 No.788 トラックの移動
ユーザー 👑 tatyamtatyam
提出日時 2019-02-08 23:02:00
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,306 bytes
コンパイル時間 2,213 ms
コンパイル使用メモリ 218,984 KB
実行使用メモリ 35,112 KB
最終ジャッジ日時 2023-09-14 03:54:51
合計ジャッジ時間 5,569 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 485 ms
35,112 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 115 ms
11,192 KB
testcase_05 AC 465 ms
34,780 KB
testcase_06 AC 477 ms
34,596 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 WA -
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 138 ms
34,656 KB
testcase_16 AC 512 ms
34,740 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<unordered_map<ll,ll>>g(n);
    rep(i,0,m){
        ll a,b,c;
        cin>>a>>b>>c;
        a--;
        b--;
        g[a][b]=c;
        g[b][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