結果

問題 No.3013 ハチマキ買い星人
ユーザー のらら
提出日時 2025-01-21 23:24:40
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 1,023 bytes
コンパイル時間 3,576 ms
コンパイル使用メモリ 179,772 KB
実行使用メモリ 46,648 KB
最終ジャッジ日時 2025-01-25 22:17:01
合計ジャッジ時間 30,826 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 39 TLE * 6
権限があれば一括ダウンロードができます

ソースコード

diff #

//bfs(TLE解法)
//入力と逆順に探索する
#include <iostream>
#include <algorithm>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
ll N, M, P, Y;

vector<vector<pair<ll, ll>>> G;
vector<ll> bfs(ll start = 0) {
  ll n = G.size();
  vector<ll> dist(n, -1);
  queue<ll> que;
  que.emplace(start);
  dist[start] = Y;
  while(!que.empty()){
    int pos = que.front(); que.pop();
    for(ll i = G[pos].size() - 1; i >= 0; i--){
      auto [to, cost] = G[pos][i];
      if(dist[pos] >= cost && dist[pos] - cost > dist[to]){
        dist[to] = dist[pos] - cost ;
        que.push(to);
      }
    }
  }
  return dist;
}

int main(){
  cin >> N >> M >> P >> Y;
  G.resize(N + 1);
  for(int i = 1; i <= M; i++){
    ll a, b, c;
    cin >> a >> b >> c;
    G[a].push_back({b, c});
    G[b].push_back({a, c});
  }
  auto ret = bfs(1);
  ll ans = 0;
  for(int i = 1; i <= P; i++){
    ll d, e;
    cin >> d >> e;
    ans = max(ans, ret[d] / e);
  }
  cout << ans << endl;
  return 0;
}
0