結果

問題 No.3013 ハチマキ買い星人
ユーザー ooaiu
提出日時 2025-02-01 20:25:10
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 233 ms / 2,000 ms
コード長 1,064 bytes
コンパイル時間 4,014 ms
コンパイル使用メモリ 285,676 KB
実行使用メモリ 17,400 KB
最終ジャッジ日時 2025-02-01 20:25:24
合計ジャッジ時間 11,148 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 45
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int N, M, P;
    ll Y;
    cin >> N >> M >> P >> Y;
    vector<vector<pair<int, int>>> adj(N);
    for (int i = 0; i < M; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        a--, b--;
        adj[a].push_back({b, c});
        adj[b].push_back({a, c});
    }
    priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<>> pq;
    pq.push({0, 0});
    vector<ll> dist(N, 1e18);
    dist[0] = 0;
    while(!pq.empty()) {
        auto [d, v] = pq.top();
        pq.pop();
        if(dist[v] != d) continue;
        for(const auto&[to, cst]: adj[v]) {
            if(dist[to] > dist[v] + cst) {
                dist[to] = dist[v] + cst;
                pq.push({dist[to], to});
            }
        }
    }
    ll ans = 0;
    while(P--) {
        int d, e;
        cin >> d >> e;
        d--;
        ll cur = Y - dist[d];
        cur /= e;
        ans = max(ans, cur);
    }
    cout << ans << '\n';
}
0