結果

問題 No.3013 ハチマキ買い星人
ユーザー srjywrdnprkt
提出日時 2025-03-12 23:30:04
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 265 ms / 2,000 ms
コード長 1,357 bytes
コンパイル時間 4,010 ms
コンパイル使用メモリ 287,864 KB
実行使用メモリ 20,976 KB
最終ジャッジ日時 2025-03-12 23:30:19
合計ジャッジ時間 14,145 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 45
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
//#include <atcoder/modint>

using namespace std;
//using namespace atcoder;
using ll = long long;
//using mint = modint998244353;

template<typename T> using pq = priority_queue<T, vector<T>, greater<T>>;

vector<ll> dijkstra(vector<vector<pair<ll, ll>>> &E, ll start){

    ll N = E.size();
    ll from, alt, d;

    pq<pair<ll, ll>> que;
    vector<ll> dist(N, 1e18);
    vector<bool> vst(N);

    dist[start] = 0;
    que.push({0, start});

    while(!que.empty()){
        tie(d, from) = que.top();
        que.pop();
        if (vst[from]) continue;
        vst[from] = 1;
        for (auto [to, C] : E[from]){
            alt = d + C;
            if (alt < dist[to]){
                dist[to] = alt;
                que.push({dist[to], to});
            }
        }
    }

    return dist;
}

int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    ll N, M, P, Y, a, b, c, ans=0;
    cin >> N >> M >> P >> Y;
    vector<vector<pair<ll, ll>>> E(N);

    for (int i=0; i<M; i++){
        cin >> a >> b >> c; a--; b--;
        E[a].push_back({b, c});
        E[b].push_back({a, c});
    }

    vector<ll> dist = dijkstra(E, 0);

    for (int i=0; i<P; i++){
        cin >> a >> b; a--;
        if (Y<dist[a]) continue;
        ans = max(ans, (Y-dist[a])/b);
    }

    cout << ans << endl;

    return 0;
}
0