結果
問題 | No.3013 ハチマキ買い星人 |
ユーザー |
|
提出日時 | 2025-01-25 14:44:44 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 433 ms / 2,000 ms |
コード長 | 1,027 bytes |
コンパイル時間 | 5,183 ms |
コンパイル使用メモリ | 286,164 KB |
実行使用メモリ | 22,500 KB |
最終ジャッジ日時 | 2025-01-25 23:28:58 |
合計ジャッジ時間 | 15,449 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge6 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 45 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; #define int ll #undef INT_MAX #define INT_MAX LLONG_MAX using xy = array<int, 2>; signed main() { int n, m, p, y; cin >> n >> m >> p >> y; vector<int> r(n, INT_MAX); vector<vector<xy>> v(n, vector<xy>(0)); for (int i = 0; i < m; i++) { int a, b, c; cin >> a >> b >> c; --a; --b; v[a].push_back({b, c}); v[b].push_back({a, c}); } for (int i = 0; i < p; i++) { int a, b; cin >> a >> b; --a; r[a] = min(r[a], b); } priority_queue<xy, vector<xy>, greater<xy>> q; q.push({0, 0}); vector<int> dist(n, INT_MAX); while (!q.empty()) { auto [c, f] = q.top(); q.pop(); dist[f] = c; for (auto [k, d] : v[f]) { if (dist[k] == INT_MAX) { q.push({c+d, k}); } } while (!q.empty() && dist[q.top()[1]] != INT_MAX) q.pop(); } int ans = 0; for (int i = 0; i < n; i++) { if (r[i] == INT_MAX) continue; ans = max(ans, (y - dist[i]) / r[i]); } cout << ans << endl; }