結果

問題 No.788 トラックの移動
ユーザー kotatsugamekotatsugame
提出日時 2019-02-08 22:52:40
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,299 bytes
コンパイル時間 764 ms
コンパイル使用メモリ 86,764 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-14 03:53:05
合計ジャッジ時間 3,823 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 409 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 96 ms
4,380 KB
testcase_05 AC 398 ms
4,376 KB
testcase_06 AC 411 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 93 ms
4,376 KB
testcase_16 AC 445 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:38:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
   38 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#include<vector>
#include<queue>
#include<limits>
template<typename T>
vector<T>dijkstra(int s,const vector<vector<pair<int,T> > >&G,T INF=numeric_limits<T>::max())
{
	int n=G.size();
	vector<T>d(n,INF);
	vector<int>parent(n,-1);
	priority_queue<pair<T,int>,vector<pair<T,int> >,greater<pair<T,int> > >P;
	d[s]=0;
	P.push(make_pair(d[s],s));
	while(!P.empty())
	{
		pair<T,int>p=P.top();P.pop();
		int v=p.second;
		if(d[v]<p.first)continue;
		for(const pair<int,T>&e:G[v])
		{
			int u=e.first;
			T cost=d[v]+e.second;
			if(d[u]>cost)
			{
				d[u]=cost;
				parent[u]=v;
				P.push(make_pair(d[u],u));
			}
		}
	}
	return d;
}
int n,m,L;
long t[2000];
main()
{
	cin>>n>>m>>L;
	int cnt=0;
	for(int i=0;i<n;i++)cin>>t[i],cnt+=!!t[i];
	if(cnt==1)cout<<0<<endl;
	vector<vector<pair<int,long> > >G(n);
	for(int i=0;i<m;i++)
	{
		int a,b;long c;cin>>a>>b>>c;
		a--;b--;
		G[a].push_back(make_pair(b,c));
		G[b].push_back(make_pair(a,c));
	}
	vector<long>off=dijkstra(L-1,G);
	long ans=9e18;
	for(int i=0;i<n;i++)
	{
		long now=0;
		long ofset=off[i];
		vector<long>a=dijkstra(i,G);
		for(int j=0;j<n;j++)
		{
			now+=t[j]*a[j]*2;
			if(t[j])ofset=min(ofset,off[j]-a[j]);
		}
		ans=min(ans,now+ofset);
	}
	cout<<ans<<endl;
}
0