結果
問題 | No.3013 ハチマキ買い星人 |
ユーザー |
|
提出日時 | 2025-01-25 12:52:07 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 222 ms / 2,000 ms |
コード長 | 965 bytes |
コンパイル時間 | 2,413 ms |
コンパイル使用メモリ | 206,052 KB |
実行使用メモリ | 17,400 KB |
最終ジャッジ日時 | 2025-01-25 22:24:56 |
合計ジャッジ時間 | 8,951 ms |
ジャッジサーバーID (参考情報) |
judge7 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 45 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; int main(){ ios::sync_with_stdio(false); cin.tie(0); int n, m; ll p, y; cin >> n >> m >> p >> y; vector<vector<pair<int,int>>> g(n); for(int i = 0; i < m; i++){ int a, b, c; cin >> a >> b >> c; a--, b--; g[a].emplace_back(b, c); g[b].emplace_back(a, c); } priority_queue<pair<ll,int>, vector<pair<ll,int>>, greater<pair<ll,int>>> pq; vector<ll> dp(n, 1ll << 60); dp[0] = 0; pq.emplace(0, 0); while(!pq.empty()){ auto [d, v] = pq.top(); pq.pop(); if(d > dp[v]) continue; for(auto [u, w] : g[v]){ if(d + w >= dp[u]) continue; dp[u] = d + w; pq.emplace(d + w, u); } } ll ans = 0; while(p--){ int v, e; cin >> v >> e; v--; ans = max(ans, (y - dp[v]) / e); } cout << ans << '\n'; }