結果
問題 | No.3013 ハチマキ買い星人 |
ユーザー |
|
提出日時 | 2025-01-25 13:17:57 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 409 ms / 2,000 ms |
コード長 | 1,326 bytes |
コンパイル時間 | 3,211 ms |
コンパイル使用メモリ | 285,196 KB |
実行使用メモリ | 22,500 KB |
最終ジャッジ日時 | 2025-01-25 22:42:04 |
合計ジャッジ時間 | 14,232 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge8 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 45 |
ソースコード
#include <bits/stdc++.h> typedef long long ll; typedef std::pair<long long, long long> P; typedef std::priority_queue<P, std::vector<P>, std::greater<P>> PQ; int main() { long long n, m, p, y; std::cin >> n >> m >> p >> y; std::vector<std::vector<P>> path(n); std::vector<long long> h(n, -1); for (int i = 0; i < m; ++i) { ll a, b, c; std::cin >> a >> b >> c; --a, --b; path[a].push_back({b, c}); path[b].push_back({a, c}); } for (int i = 0; i < p; ++i) { ll d, e; std::cin >> d >> e; --d; h[d] = e; } std::vector<long long> dist(n, 1e17); dist[0] = 0; PQ pq; pq.push({0, 0}); while (!pq.empty()) { ll udist = pq.top().first; ll u = pq.top().second; pq.pop(); if (udist > dist[u]) continue; for (auto edge : path[u]) { ll v = edge.first; ll c = edge.second; if (dist[v] > udist + c) { dist[v] = udist + c; pq.push({udist + c, v}); } } } ll ans = 0; for (int i = 0; i < n; ++i) { if (h[i] == -1) continue; if (dist[i] > 1e16) continue; ll r = y - dist[i]; ans = std::max(ans, r / h[i]); } std::cout << ans << std::endl; }