結果

問題 No.788 トラックの移動
ユーザー beetbeet
提出日時 2019-02-08 22:00:32
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,685 bytes
コンパイル時間 2,375 ms
コンパイル使用メモリ 209,396 KB
実行使用メモリ 35,416 KB
最終ジャッジ日時 2023-09-14 03:39:57
合計ジャッジ時間 5,697 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 443 ms
35,164 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 108 ms
19,360 KB
testcase_05 AC 435 ms
35,140 KB
testcase_06 AC 440 ms
35,176 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 RE -
testcase_14 RE -
testcase_15 AC 137 ms
35,168 KB
testcase_16 AC 465 ms
35,416 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


template <typename T>
vector<T> dijkstra(Int s,vector<vector<pair<Int, T> > > & G){  
  const T INF = numeric_limits<T>::max();    
  using P = pair<T, Int>;
  Int n=G.size();
  vector<T> d(n,INF);
  vector<Int> b(n,-1);
  priority_queue<P,vector<P>,greater<P> > q;
  d[s]=0;
  q.emplace(d[s],s);
  while(!q.empty()){
    P p=q.top();q.pop();
    Int v=p.second;
    if(d[v]<p.first) continue;
    for(auto& e:G[v]){
      Int u=e.first;
      T c=e.second;
      if(d[u]>d[v]+c){
        d[u]=d[v]+c;
        b[u]=v;
        q.emplace(d[u],u);
      }
    }
  }
  return d;
}

//INSERT ABOVE HERE
const Int MAX = 2020;
Int dist[MAX][MAX];
signed main(){
  Int n,m,l;
  cin>>n>>m>>l;
  l--;
  vector<Int> t(n);
  for(Int i=0;i<n;i++) cin>>t[i];
  
  {
    Int sum=0;
    for(Int i=0;i<n;i++) sum+=t[i];
    if(*max_element(t.begin(),t.end())==sum) assert(0);
  }
  
  using P = pair<Int, Int>;
  vector<vector<P> > G(n);
  for(Int i=0;i<m;i++){
    Int a,b,c;
    cin>>a>>b>>c;
    a--;b--;
    G[a].emplace_back(b,c);
    G[b].emplace_back(a,c);
  }
  for(Int i=0;i<n;i++){
    auto dp=dijkstra(i,G);
    for(Int j=0;j<n;j++) dist[i][j]=dp[j];
  }
  Int ans=1e18;
  for(Int i=0;i<n;i++){
    Int res=0;
    for(Int j=0;j<n;j++)
      res+=dist[i][j]*t[j]*2;

    Int tmp=0;
    for(Int j=0;j<n;j++)
      if(t[j]) chmax(tmp,dist[i][j]-dist[l][j]);
    
    //cout<<i<<" "<<res<<" "<<tmp<<endl;
    chmin(ans,res-tmp);
  }
  
  cout<<ans<<endl;
  return 0;
}
0