結果

問題 No.3013 ハチマキ買い星人
ユーザー 回転
提出日時 2025-01-25 16:24:18
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
RE  
実行時間 -
コード長 1,352 bytes
コンパイル時間 1,252 ms
コンパイル使用メモリ 110,796 KB
実行使用メモリ 7,928 KB
最終ジャッジ日時 2025-01-25 23:52:41
合計ジャッジ時間 9,212 ms
ジャッジサーバーID
(参考情報)
judge6 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other WA * 2 RE * 43
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
using namespace std;

struct Edge {
    int to, cost;
};

int main() {
    int N, M, P, Y;
    cin >> N >> M >> P >> Y;

    vector<vector<Edge>> edge(N);
    for (int i = 0; i < M; ++i) {
        int a, b, c;
        cin >> a >> b >> c;
        --a; // 0-indexed
        --b; // 0-indexed
        edge[a].push_back({b, c});
        edge[b].push_back({a, c});
    }

    vector<pair<int, int>> shop(P);
    for (int i = 0; i < P; ++i) {
        int d, e;
        cin >> d >> e;
        shop[i] = {d - 1, e}; // 0-indexed
    }

    priority_queue<pair<int, int>> q; // {money, node}
    q.push({Y, 0});

    vector<int> money_s(N, 0);
    while (!q.empty()) {
        int money = q.top().first;
        int now = q.top().second;
        q.pop();

        if (money_s[now] >= money) continue;
        money_s[now] = money;

        for (const auto& e : edge[now]) {
            int next_money = money - e.cost;
            if (next_money > money_s[e.to]) {
                q.push({next_money, e.to});
            }
        }
    }

    int ans = INT_MIN;
    for (const auto& s : shop) {
        int d = s.first, e = s.second;
        if (money_s[d] > 0) {
            ans = max(ans, money_s[d] / e);
        }
    }

    cout << ans << endl;
    return 0;
}
0