結果

問題 No.3013 ハチマキ買い星人
ユーザー it_is_a_pity_
提出日時 2025-01-25 20:17:21
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 255 ms / 2,000 ms
コード長 1,512 bytes
コンパイル時間 4,019 ms
コンパイル使用メモリ 233,212 KB
実行使用メモリ 31,936 KB
最終ジャッジ日時 2025-01-26 00:06:43
合計ジャッジ時間 11,183 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 45
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:51:18: warning: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   51 |         for(auto [next,c]:G[now]){
      |                  ^

ソースコード

diff #

#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<(ll)n;i++)
#define all(v) v.begin(),v.end()
const ll INF = (ll)2e18;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll N, M, P, Y;
    cin >> N >> M >> P >> Y;
    ll ans = 0;
    vector<ll> A(M), B(M), C(M);
    vector<vector<pair<ll, ll>>> G(N);

    rep(i,M){
        cin >> A[i] >> B[i] >> C[i];
        A[i]--;
        B[i]--;
        G[A[i]].push_back({B[i], C[i]});
        G[B[i]].push_back({A[i], C[i]});
    }
    unordered_map<ll, ll> memo;
    vector<bool> valid(N, false);
    vector<ll> D(P), E(P);

    rep(i,P){
        cin >> D[i] >> E[i];
        D[i]--;
        valid[D[i]] = true;
        memo[D[i]] = E[i];
    }
    vector<ll> dist(N, INF);
    dist[0] = 0;
    priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> pq;
    pq.push({0, 0});
    while(!pq.empty()){
        ll now = pq.top().second;
        ll d = pq.top().first;
        pq.pop();
        if(d!=dist[now]){
            continue;
        }
        for(auto [next,c]:G[now]){
            if(dist[next]>dist[now]+c){
                dist[next] = dist[now] + c;
                pq.push({dist[next], next});
            }
        }
    }
    rep(i,N){
        if(dist[i]>=Y||!valid[i]){
            continue;
        }
        ans = max(ans, (Y - dist[i]) / memo[i]);
    }
    cout << ans << endl;
}
0