結果

問題 No.2739 Time is money
ユーザー Nzt3
提出日時 2024-04-15 23:25:08
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 972 bytes
コンパイル時間 2,237 ms
コンパイル使用メモリ 207,812 KB
最終ジャッジ日時 2025-02-21 02:22:44
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 15 WA * 3
権限があれば一括ダウンロードができます

ソースコード

diff #

// overflow WA

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr int MOD=998244353;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N,M,X;
  cin>>N>>M>>X;
  vector G(N,vector(0,array<int,3>()));
  for(int i=0;i<M;i++){
    int U,V,C,T;
    cin>>U>>V>>C>>T;
    --U,--V;
    G[U].push_back({V,C,T});
    G[V].push_back({U,C,T});
  }
  vector dist(N,array<int,2>({(int)1e9,0ll}));
  dist[0]={0,0};
  using pq_pair=pair<array<int,2>,int>;
  priority_queue<pq_pair,vector<pq_pair>,greater<pq_pair>>pq;
  pq.push(make_pair(array<int,2>({0,0}),0));
  while(pq.size()){
    auto [d,v]=pq.top();
    pq.pop();
    if(d>dist[v])continue;
    for(auto [to,c,t]:G[v]){
      array<int,2>d2=d;
      int k=(c+d2[1]+X-1)/X;
      d2[0]+=t+k;
      d2[1]=-(k*X-d[1]-c);
      if(dist[to]>d2){
        dist[to]=d2;
        pq.push(make_pair(d2,to));
      }
    }
  }
  if(dist[N-1][0]==1e9)cout<<"-1\n";
  else cout<<dist[N-1][0]<<'\n';
}
0