結果

問題 No.788 トラックの移動
ユーザー eQeeQe
提出日時 2019-04-16 19:59:02
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,429 bytes
コンパイル時間 1,422 ms
コンパイル使用メモリ 168,340 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-22 07:11:04
合計ジャッジ時間 4,453 ms
ジャッジサーバーID
(参考情報)
judge14 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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];
ll d[2020];

void dijkstra(ll s) {
  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++) {
    dijkstra(i);
    ll t=0;
    for(j=0; j<N; j++) {
      t+=d[j]*2*c[j];
    }
    
    t+=d[L];
    chmin(ans, t);
  }
  
  pt(ans);
}




0