結果

問題 No.3013 ハチマキ買い星人
ユーザー forest3
提出日時 2025-02-03 22:48:05
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 491 ms / 2,000 ms
コード長 948 bytes
コンパイル時間 2,618 ms
コンパイル使用メモリ 171,532 KB
実行使用メモリ 21,592 KB
最終ジャッジ日時 2025-02-03 22:48:25
合計ジャッジ時間 15,066 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 45
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++ )
using ll = long long;

int main() {
	int N, M, p;
	ll Y;
	cin >> N >> M >> p >> Y;
	using P = pair<ll, int>;
	vector<vector<P>> g(N);
	rep(i, M) {
		int a, b, c;
		cin >> a >> b >> c;
		a--;
		b--;
		g[a].push_back(P(c, b));
		g[b].push_back(P(c, a));
	}
	vector<int> s(N);
	rep(i, p) {
		int d, e;
		cin >> d >> e;
		d--;
		s[d] = e;
	}
	ll INF = 2e18;
	vector<ll> cost(N, INF);
	cost[0] = 0;
	priority_queue<P, vector<P>, greater<P>> q;
	q.push(P(0, 0));
	while(q.size()) {
		ll c;
		int u;
		tie(c, u) = q.top();
		q.pop();
		if(c > cost[u]) continue;
		for(P p : g[u]) {
			ll co = p.first;
			int v = p.second;
			if(cost[v] > c + co) {
				cost[v] = c + co;
				q.push(P(cost[v], v));
			}
		}
	}
	ll ans = 0;
	rep(i, N) {
		if(cost[i] == INF) continue;
		ll r = max(0LL, Y - cost[i]);
		if(s[i]) ans = max(ans, r / s[i]);
	}
	cout << ans << endl;
}
0