結果

問題 No.788 トラックの移動
ユーザー addeight2addeight2
提出日時 2019-02-09 16:17:25
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,092 bytes
コンパイル時間 1,318 ms
コンパイル使用メモリ 152,892 KB
実行使用メモリ 34,972 KB
最終ジャッジ日時 2023-09-14 11:46:24
合計ジャッジ時間 4,837 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 469 ms
34,680 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 107 ms
19,272 KB
testcase_05 AC 460 ms
34,972 KB
testcase_06 AC 472 ms
34,708 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 137 ms
34,656 KB
testcase_16 AC 506 ms
34,704 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
	
using namespace std;
const int MAX_N=2e3;
const ll INF=1e18;
struct edge{
	int to;
	ll cst;
	edge(int t=-1,ll c=0):to(t),cst(c){}
};
vector<edge> G[MAX_N];
int N,M,L;
ll t[MAX_N];
ll dst[MAX_N][MAX_N];
typedef pair<ll,int> P;
void dijk(int s){
	REP(v,N)dst[s][v]=INF;
	dst[s][s]=0;
	priority_queue<P,vector<P>,greater<P> > pque;
	pque.push(P(0,s));
	while(!pque.empty()){
		P p=pque.top();
		pque.pop();
		int v=p.second;
		if(p.first>dst[s][v])continue;
		for(auto e:G[v]){
			if(dst[s][e.to]>dst[s][v]+e.cst){
				dst[s][e.to]=dst[s][v]+e.cst;
				pque.push(P(dst[s][e.to],e.to));
			}
		}
	}
}
int main(){
	cin>>N>>M>>L;
	L--;
	REP(i,N)cin>>t[i];
	REP(i,M){
		int a,b;
		ll c;
		cin>>a>>b>>c;
		a--;
		b--;
		G[a].push_back(edge(b,c));
		G[b].push_back(edge(a,c));
	}
	REP(i,N){
		dijk(i);
	}
	ll ans=INF;
	REP(v,N){
		ll sm=0;
		REP(i,N){
			sm+=2*t[i]*dst[v][i];
		}
		REP(u,N){
			if(t[u]>0){
				ans=min(ans,sm+dst[L][u]-dst[u][v]);
			}
		}
	}
	cout<<ans<<endl;
}
0