結果

問題 No.788 トラックの移動
ユーザー eQeeQe
提出日時 2019-04-16 21:13:12
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 840 ms / 2,000 ms
コード長 1,740 bytes
コンパイル時間 1,243 ms
コンパイル使用メモリ 152,736 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-21 17:31:56
合計ジャッジ時間 6,344 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 835 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 194 ms
4,380 KB
testcase_05 AC 819 ms
4,376 KB
testcase_06 AC 840 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 136 ms
4,380 KB
testcase_16 AC 643 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define ft first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=1e5+7;
static const ll MOD=1e9+7;



class Edge {
public:
  ll t, w;
  Edge(ll t, ll w): t(t), w(w) {}
};

ll N, M, L;
vector<Edge> g[2020];

void dijkstra(ll s, ll d[]) {
  ll i, u;
  ll clr[2020];
  for(i=0; i<N; i++) {
    d[i]=INF;
    clr[i]=0;
  }
  priority_queue<P> q;
  q.push(P(0, s));
  d[s]=0;
  
  while(q.size()) {
    P f=q.top(); q.pop();
    u=f.sc;
    
    clr[u]=1;
    if(d[u]<-f.ft) continue;
    
    for(i=0; i<g[u].size(); i++) {
      Edge &e=g[u][i];
      if(clr[e.t]==0 && d[e.t]>d[u]+e.w) {
        d[e.t]=d[u]+e.w;
        q.push(P(-d[e.t], e.t));
      }
    }
  }
}


int main(void) {
  cin >> N >> M >> L;
  L--;
  ll c[2020];
  ll i, j;
  
  for(i=0; i<N; i++) {
    cin >> c[i];
  }
  
  for(i=0; i<M; i++) {
    ll a, b, c;
    cin >> a >> b >> c;
    a--; b--;
    g[a].pb(Edge(b, c));
    g[b].pb(Edge(a, c));
  }
  
  ll ans=INF;
  for(i=0; i<N; i++) {
    ll ds[2020]={};
    dijkstra(i, ds);
    
    
    ll t=0;
    for(j=0; j<N; j++) {
      t+=ds[j]*2*c[j];
    }
    
    ll dl[2020]={};
    dijkstra(L, dl);
    for(j=0; j<N; j++) {
      ll tm=t;
      if(c[j]==0) continue;
      tm+=dl[j];
      tm+=ds[j];
      tm-=ds[j]*2;
      chmin(ans, tm);
    }
    
    ll f=1;
    for(j=0; j<N; j++) {
      if(j==i) continue;
      if(c[j]>0) f=0;
    }
    
    if(f) ans=0;
    
  }
  
  pt(ans);
}




0