結果

問題 No.3013 ハチマキ買い星人
ユーザー elphe
提出日時 2025-02-11 13:54:44
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 138 ms / 2,000 ms
コード長 1,442 bytes
コンパイル時間 1,666 ms
コンパイル使用メモリ 102,364 KB
実行使用メモリ 20,524 KB
最終ジャッジ日時 2025-02-11 13:54:55
合計ジャッジ時間 6,655 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 45
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdint>
#include <vector>
#include <tuple>
#include <queue>

using namespace std;

template<typename T> constexpr T chmax(T& variable, const T value) noexcept
{
	if (variable < value) return (variable = value);
	else return variable;
}

int main()
{
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	
	uint32_t N, M, P;
	uint64_t Y;
	cin >> N >> M >> P >> Y;
	vector<tuple<uint32_t, uint32_t, uint32_t>> edges(M);
	vector<pair<uint32_t, uint32_t>> shops(P);
	for (auto& edge : edges)
		cin >> get<0>(edge) >> get<1>(edge) >> get<2>(edge);
	for (auto& shop : shops)
		cin >> shop.first >> shop.second;

	vector<vector<pair<uint32_t, uint32_t>>> edges_from(N);
	for (const auto& edge : edges)
	{
		edges_from[get<0>(edge) - 1].emplace_back(get<1>(edge) - 1, get<2>(edge));
		edges_from[get<1>(edge) - 1].emplace_back(get<0>(edge) - 1, get<2>(edge));
	}

	vector<uint64_t> money(N, 0);
	priority_queue<pair<uint64_t, uint32_t>> pq;
	money[0] = Y, pq.emplace(Y, 0);
	while (!pq.empty())
	{
		const auto cur = pq.top();
		pq.pop();

		if (cur.first != money[cur.second]) continue;
		for (const auto& edge : edges_from[cur.second])
			if (cur.first > money[edge.first] + edge.second)
				money[edge.first] = cur.first - edge.second, pq.emplace(money[edge.first], edge.first);
	}

	uint64_t ans = 0;
	for (const auto& shop : shops)
		chmax(ans, money[shop.first - 1] / shop.second);

	cout << ans << '\n';
	return 0;
}
0