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