結果

問題 No.788 トラックの移動
ユーザー chocoruskchocorusk
提出日時 2019-02-08 22:02:35
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,467 bytes
コンパイル時間 759 ms
コンパイル使用メモリ 99,468 KB
実行使用メモリ 35,088 KB
最終ジャッジ日時 2023-09-14 03:40:07
合計ジャッジ時間 3,812 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 396 ms
34,800 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 94 ms
19,460 KB
testcase_05 AC 391 ms
35,088 KB
testcase_06 AC 401 ms
34,812 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 102 ms
34,808 KB
testcase_16 AC 428 ms
34,804 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef pair<ll, int> P;
const ll INF=1e16;
int n, m, l;
ll t[2001];
vector<P> g[2001];
ll d[2001][2001];
int main()
{
	cin>>n>>m>>l;
	l--;
	for(int i=0; i<n; i++) cin>>t[i];
	for(int i=0; i<m; i++){
		int a, b; ll c;
		cin>>a>>b>>c; a--; b--;
		g[a].push_back(P(c, b));
		g[b].push_back(P(c, a));
	}
	for(int i=0; i<n; i++){
		fill(d[i], d[i]+n, INF);
		d[i][i]=0;
		priority_queue<P, vector<P>, greater<P>> que;
		que.push(P(0, i));
		while(!que.empty()){
			P p=que.top(); que.pop();
			int x=p.second;
			if(d[i][x]<p.first) continue;
			for(auto q:g[x]){
				int y=q.second;
				if(d[i][y]>d[i][x]+q.first){
					d[i][y]=d[i][x]+q.first;
					que.push(P(d[i][y], y));
				}
			}
		}
	}
	ll ans=INF;
	for(int i=0; i<n; i++){
		ll ans1=0;
		if(t[l]>0){
			ans1=d[l][i];
			for(int j=0; j<n; j++){
				if(l==j) ans1+=d[i][j]*(t[j]-1)*2;
				else ans1+=d[i][j]*t[j]*2;
			}
		}else{
			ll mn=INF;
			for(int j=0; j<n; j++){
				if(t[j]) mn=min(mn, d[l][j]+d[j][i]);
			}
			ans1=mn;
			for(int j=0; j<n; j++){
				ans1+=d[i][j]*t[j]*2;
			}
		}
		ans=min(ans, ans1);
	}
	cout<<ans<<endl;
	return 0;
}
0