結果

問題 No.3013 ハチマキ買い星人
ユーザー YFYF
提出日時 2025-01-25 12:57:48
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 362 ms / 2,000 ms
コード長 1,928 bytes
コンパイル時間 4,319 ms
コンパイル使用メモリ 259,376 KB
実行使用メモリ 20,940 KB
最終ジャッジ日時 2025-01-25 22:27:31
合計ジャッジ時間 16,693 ms
ジャッジサーバーID
(参考情報)
judge10 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 45
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
struct Edge {
    long long to;
    long long cost;
};
using Graph = vector<vector<Edge>>;
using P = pair<long, int>;
const long long INF = 1LL << 60;
/* dijkstra(G,s,dis)
    入力:グラフ G, 開始点 s, 距離を格納する dis
    計算量:O(|E|log|V|)
    副作用:dis が書き換えられる
*/
void dijkstra(const Graph &G, int s, vector<long long> &dis) {
    int N = G.size();
    dis.resize(N, INF);
    priority_queue<P, vector<P>, greater<P>> pq;  // 「仮の最短距離, 頂点」が小さい順に並ぶ
    dis[s] = 0;
    pq.emplace(dis[s], s);
    while (!pq.empty()) {
        P p = pq.top();
        pq.pop();
        int v = p.second;
        if (dis[v] < p.first) {  // 最短距離で無ければ無視
            continue;
        }
        for (auto &e : G[v]) {
            if (dis[e.to] > dis[v] + e.cost) {  // 最短距離候補なら priority_queue に追加
                dis[e.to] = dis[v] + e.cost;
                pq.emplace(dis[e.to], e.to);
            }
        }
    }
}

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

    Graph G(N);
    rep(i,M){
        long long a,b,c;
        cin >> a >> b >> c;
        a--;
        b--;

        G[a].push_back({b,c});
        G[b].push_back({a,c});
    }

    vector<long long> dis;
    dijkstra(G,0,dis);

    // rep(i,N){
    //     cout << dis[i] << endl;
    // }

    long long res = 0;

    rep(i,P){
        long long d,e;
        cin >> d >> e;
        d--;

        if(Y - dis[d] > 0)chmax(res,(Y - dis[d]) / e);
    }

    cout << res << endl;  
}
0