結果

問題 No.788 トラックの移動
ユーザー chocoruskchocorusk
提出日時 2019-02-08 22:25:24
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 506 ms / 2,000 ms
コード長 1,388 bytes
コンパイル時間 1,082 ms
コンパイル使用メモリ 100,188 KB
実行使用メモリ 34,816 KB
最終ジャッジ日時 2023-08-21 17:27:31
合計ジャッジ時間 4,380 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 466 ms
34,764 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 108 ms
19,340 KB
testcase_05 AC 455 ms
34,816 KB
testcase_06 AC 467 ms
34,764 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 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 1 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 137 ms
34,736 KB
testcase_16 AC 506 ms
34,764 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--;
	int c=0;
	for(int i=0; i<n; i++){
		cin>>t[i];
		if(t[i]) c++;
	}
	if(c==1){
		cout<<0<<endl;
		return 0;
	}
	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;
		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