結果

問題 No.788 トラックの移動
ユーザー addeight2addeight2
提出日時 2019-02-10 09:44:43
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 457 ms / 2,000 ms
コード長 1,171 bytes
コンパイル時間 1,321 ms
コンパイル使用メモリ 152,916 KB
実行使用メモリ 34,852 KB
最終ジャッジ日時 2023-08-21 17:30:11
合計ジャッジ時間 4,543 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 433 ms
34,852 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 100 ms
19,488 KB
testcase_05 AC 425 ms
34,728 KB
testcase_06 AC 437 ms
34,832 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 136 ms
34,724 KB
testcase_16 AC 457 ms
34,752 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]);
			}
		}
	}
	int flg=0;
	REP(v,N){
		if(t[v]>0){
			flg++;
		}
	}
	if(flg==1){
		ans=0;
	}
	cout<<ans<<endl;
}
0