結果

問題 No.788 トラックの移動
ユーザー leaf_1415leaf_1415
提出日時 2019-02-08 22:06:10
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,400 bytes
コンパイル時間 885 ms
コンパイル使用メモリ 69,628 KB
実行使用メモリ 35,060 KB
最終ジャッジ日時 2023-09-14 03:41:14
合計ジャッジ時間 4,064 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 459 ms
34,916 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 109 ms
19,384 KB
testcase_05 AC 446 ms
35,060 KB
testcase_06 AC 460 ms
35,040 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 81 ms
35,020 KB
testcase_16 AC 477 ms
34,908 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <queue>
#define llint long long
#define inf 1e18

using namespace std;

typedef pair<llint, llint> P;

struct edge{
	llint to, cost;
	edge(llint a, llint b){
		to = a, cost = b;
	}
};

llint n, m, l;
llint t[2005];
vector<edge> G[2005];
llint dist[2005][2005];

void dijkstra(llint S, llint dist[])
{
	for(int i = 1; i <= n; i++) dist[i] = inf;
	dist[S] = 0;
	
	priority_queue< P, vector<P>, greater<P> > Q;
	Q.push( make_pair(0, S) );
	
	llint v, d;
	while(Q.size()){
		d = Q.top().first;
		v = Q.top().second;
		Q.pop();
		if(dist[v] < d) continue;
		for(int i = 0; i < G[v].size(); i++){
			if(dist[G[v][i].to] > d + G[v][i].cost){
				dist[G[v][i].to] = d + G[v][i].cost;
				Q.push( make_pair(dist[G[v][i].to], G[v][i].to) );
			}
		}
	}
}

int main(void)
{
	cin >> n >> m >> l;
	for(int i = 1; i <= n; i++) cin >> t[i];
	
	llint u, v, w;
	for(int i = 0; i < m; i++){
		cin >> u >> v >> w;
		G[u].push_back(edge(v, w));
		G[v].push_back(edge(u, w));
	}
	
	for(int i = 1; i <= n; i++) dijkstra(i, dist[i]);
	
	llint ans = inf;
	for(int i = 1; i <= n; i++){
		llint tmp = 0;
		for(int j = 1; j <= n; j++){
			if(t[j] == 0) continue;
			tmp = max(tmp, dist[l][i] + dist[i][j] - dist[l][j]);
		}
		tmp *= -1;
		tmp += dist[l][i];
		for(int j = 1; j <= n; j++) tmp += t[j] * dist[i][j] * 2;
		ans = min(ans, tmp);
	}
	cout << ans << endl;
	
	return 0;
}
0