結果

問題 No.788 トラックの移動
ユーザー aa
提出日時 2019-03-06 21:24:17
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,455 bytes
コンパイル時間 1,784 ms
コンパイル使用メモリ 174,284 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-05 19:12:57
合計ジャッジ時間 2,608 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 1 ms
4,380 KB
testcase_02 WA -
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 85 ms
4,380 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"

using namespace std;

void solve()
{
	int n, m, l;
	cin >> n >> m >> l;
	l--;
	vector<int> ts(n), ds(n, 1<<20);
	for (int i = 0; i < n; i++)
	{
		cin >> ts[i];
	}
	vector<pair<int, int>> g[n];
	while(m--)
	{
		int u, v, w;
		cin >> u >> v >> w;
		u--, v--;
		g[u].emplace_back(v, w);
		g[v].emplace_back(u, w);
	}
	priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
	pq.push(make_pair(0, l));
	ds[l] = 0;
	while (!pq.empty())
	{
		auto p = pq.top();
		pq.pop();
		int v = p.second, x = p.first;
		for (auto np : g[v])
		{
			int nv = np.first, nw = np.second;
			if (ds[nv] <= x + nw)
				continue;
			ds[nv] = x + nw;
			pq.push(make_pair(ds[nv], nv));
		}
	}
	long ans = LONG_MAX;
	for (int s = 0; s < n; s++)
	{
		vector<int> d(n, 1<<20);
		pq.push(make_pair(0, s));
		d[s] = 0;
		while(!pq.empty())
		{
			auto p = pq.top();
			pq.pop();
			int v = p.second, x = p.first;
			for (auto np : g[v])
			{
				int nv = np.first, nw = np.second;
				if (d[nv] <= x + nw) continue;
				d[nv] = x + nw;
				pq.push(make_pair(d[nv], nv));
			}
		}
		/*
		for (int dx : d){ cout << dx << ' ';}
		cout << endl;
		*/
		long res = 0;
		int p = 0;
		for (int j = 0; j < n; j++)
		{
			res += 2*ts[j]*d[j];
			p = min(p, ds[j] - d[j]);
		}
		ans = min(ans, res+p);
		//cout << res << ' ' << p << endl;
	}
	cout << ans << endl;
}

int main(void)
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}
0