結果

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

ソースコード

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<int, ll>;
	vector<vector<P>> g(N);
	rep(i, M) {
		int a, b, c;
		cin >> a >> b >> c;
		a--;
		b--;
		g[a].push_back(P(b, c));
		g[b].push_back(P(a, c));
	}
	vector<int> s(N), v(N);
	rep(i, p) {
		int d, e;
		cin >> d >> e;
		d--;
		s[d] = e;
	}
	vector<ll> h(N);
	queue<P> q;
	q.push(P(0, Y));
	v[0] = 1;
	if(s[0]) h[0] = Y / s[0];
	while(q.size()) {
		int u;
		ll y;
		tie(u, y) = q.front();
		q.pop();
		for(P p : g[u]) {
			int t = p.first;
			if(v[t]) continue;
			v[t] = 1;
			ll l = p.second;
			ll r = max(0LL, y - l);
			if(s[t]) h[t] = r / s[t];
			if(r) q.push(P(t, r));
		}
	}
	ll ans = 0;
	rep(i, N) ans = max(ans, h[i]);
	cout << ans << endl;
}
0