結果

問題 No.3013 ハチマキ買い星人
ユーザー applejam
提出日時 2025-01-25 13:01:10
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 1,120 ms / 2,000 ms
コード長 1,355 bytes
コンパイル時間 2,824 ms
コンパイル使用メモリ 158,684 KB
実行使用メモリ 65,036 KB
最終ジャッジ日時 2025-01-25 22:31:01
合計ジャッジ時間 23,704 ms
ジャッジサーバーID
(参考情報)
judge5 / judge7
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 45
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using mint = modint998244353;
#define rep(i, n) for (int i = 0; i< (int)(n); i++) 
using node = pair<ll, int>;
ll inf = 4e18;

int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int n, m, p; ll y; cin >> n >> m >> p >> y;
    map<int, set<int>> adj;
    map<pair<int, int>, ll> edges;
    rep(i, m){
        int a, b; ll c; cin >> a >> b >> c;
        adj[a].insert(b);
        adj[b].insert(a);
        edges[{a, b}] = c;
        edges[{b, a}] = c;
    }
    vector<ll> dist(n+1, inf); dist[1] = 0;
    priority_queue<node, vector<node>, greater<node>> pq;
    pq.push({0, 1});
    while(!pq.empty()){
        node u = pq.top(); pq.pop();
        if(u.first > dist[u.second])continue;
        for(auto v : adj[u.second]){
            ll alt = dist[u.second] + edges[{u.second, v}];
            if(alt < dist[v]){
                dist[v] = alt;
                pq.push({alt, v});
            }
        }
    }
    ll ans = 0;
    rep(i, p){
        int d; ll e; cin >> d >> e;
        if(dist[d] == inf)continue;
        if(dist[d] >= y)continue;
        ans = max(ans, (y-dist[d])/e);
    }
    cout << ans << endl;

    return 0;
}
0