結果
問題 | No.788 トラックの移動 |
ユーザー |
|
提出日時 | 2019-02-08 23:49:59 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 475 ms / 2,000 ms |
コード長 | 1,321 bytes |
コンパイル時間 | 1,886 ms |
コンパイル使用メモリ | 181,528 KB |
実行使用メモリ | 34,688 KB |
最終ジャッジ日時 | 2024-12-15 07:01:27 |
合計ジャッジ時間 | 5,127 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 14 |
ソースコード
#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; }