結果
問題 |
No.788 トラックの移動
|
ユーザー |
👑 ![]() |
提出日時 | 2019-02-08 23:02:00 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,306 bytes |
コンパイル時間 | 2,573 ms |
コンパイル使用メモリ | 213,252 KB |
最終ジャッジ日時 | 2025-01-06 21:02:49 |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 11 WA * 3 |
ソースコード
#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; }