結果

問題 No.3013 ハチマキ買い星人
コンテスト
ユーザー Rumain831
提出日時 2026-08-30 04:54:33
言語 C++23(gcc16)
(gcc 16.1.0 + boost 1.92.0)
コンパイル:
g++-16 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 283 ms / 2,000 ms
+ 581µs
コード長 932 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,112 ms
コンパイル使用メモリ 202,500 KB
実行使用メモリ 22,652 KB
最終ジャッジ日時 2026-08-30 04:55:04
合計ジャッジ時間 10,933 ms
ジャッジサーバーID
(参考情報)
judge3_1 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 45
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

int main(void){
  ll n, m, p, y; cin >> n >> m >> p >> y;
  vector<vector<P>> to(n);
  for(int i=0; i<m; i++){
    int u, v; ll w; cin >> u >> v >> w; u--, v--;
    to[u].emplace_back(v, w); swap(u, v);
    to[u].emplace_back(v, w);
  }
  vector<ll> d(p), e(p);
  for(int i=0; i<p; i++) cin >> d[i] >> e[i], d[i]--;
  priority_queue<P, vector<P>, greater<P>> pri;
  pri.emplace(0, 0);
  vector<ll> dist(n, 1e18);
  dist[0]=0;
  while(pri.size()){
    auto [d, id]=pri.top(); pri.pop();
    if(dist[id]!=d) continue;
    for(auto [v, w]:to[id]){
      ll nd=d+w;
      if(dist[v]>nd){
        dist[v]=nd;
        pri.emplace(nd, v);
      }
    }
  }
  ll ans=0;
  for(int i=0; i<p; i++){
    ll rem=max(0ll, y-dist[d[i]]);
    ans=max(ans, rem/e[i]);
  }
  cout << ans << endl;
  return 0; 
}
0