結果

問題 No.788 トラックの移動
ユーザー aa
提出日時 2019-03-06 21:51:23
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 418 ms / 2,000 ms
コード長 1,560 bytes
コンパイル時間 1,899 ms
コンパイル使用メモリ 177,316 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-21 17:31:30
合計ジャッジ時間 4,716 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include "bits/stdc++.h"

using namespace std;

void solve()
{
	int n, m, l;
	cin >> n >> m >> l;
	l--;
	//testcaseのmissとか抜かしてすみませんでしたm(_ _)m
	vector<long> ts(n), ds(n, 1L<<40);
	for (int i = 0; i < n; i++)
	{
		cin >> ts[i];
	}
	vector<pair<int, long>> 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<long, int>, vector<pair<long, int>>, greater<pair<long, int>>> pq;
	pq.push(make_pair(0, l));
	ds[l] = 0;
	while (!pq.empty())
	{
		auto p = pq.top();
		pq.pop();
		int v = p.second;
		long x = p.first;
		for (auto np : g[v])
		{
			int nv = np.first;
			long 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<long> d(n, 1L<<40);
		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, p = LONG_MAX;
		for (int j = 0; j < n; j++)
		{
			res += 2*ts[j]*d[j];
			p = min(p, ds[j]-d[j]*(ts[j]>0));
		}
		ans = min(ans, max(0L, res+p));
		//cout << res << ' ' << p << endl;
	}
	cout << ans << endl;
}

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