結果
問題 | No.788 トラックの移動 |
ユーザー |
![]() |
提出日時 | 2019-02-10 09:44:43 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 415 ms / 2,000 ms |
コード長 | 1,171 bytes |
コンパイル時間 | 1,559 ms |
コンパイル使用メモリ | 168,576 KB |
実行使用メモリ | 34,896 KB |
最終ジャッジ日時 | 2024-12-15 07:02:48 |
合計ジャッジ時間 | 4,210 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 14 |
ソースコード
#include <bits/stdc++.h> typedef long long ll; #define FOR(i,a,b) for(int i=(a);i<(b);i++) #define REP(i,a) FOR(i,0,a) using namespace std; const int MAX_N=2e3; const ll INF=1e18; struct edge{ int to; ll cst; edge(int t=-1,ll c=0):to(t),cst(c){} }; vector<edge> G[MAX_N]; int N,M,L; ll t[MAX_N]; ll dst[MAX_N][MAX_N]; typedef pair<ll,int> P; void dijk(int s){ REP(v,N)dst[s][v]=INF; dst[s][s]=0; priority_queue<P,vector<P>,greater<P> > pque; pque.push(P(0,s)); while(!pque.empty()){ P p=pque.top(); pque.pop(); int v=p.second; if(p.first>dst[s][v])continue; for(auto e:G[v]){ if(dst[s][e.to]>dst[s][v]+e.cst){ dst[s][e.to]=dst[s][v]+e.cst; pque.push(P(dst[s][e.to],e.to)); } } } } int main(){ cin>>N>>M>>L; L--; REP(i,N)cin>>t[i]; REP(i,M){ int a,b; ll c; cin>>a>>b>>c; a--; b--; G[a].push_back(edge(b,c)); G[b].push_back(edge(a,c)); } REP(i,N){ dijk(i); } ll ans=INF; REP(v,N){ ll sm=0; REP(i,N){ sm+=2*t[i]*dst[v][i]; } REP(u,N){ if(t[u]>0){ ans=min(ans,sm+dst[L][u]-dst[u][v]); } } } int flg=0; REP(v,N){ if(t[v]>0){ flg++; } } if(flg==1){ ans=0; } cout<<ans<<endl; }