結果

問題 No.2739 Time is money
ユーザー zatsu308zatsu308
提出日時 2024-04-20 13:40:31
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 209 ms / 2,000 ms
コード長 1,694 bytes
コンパイル時間 2,172 ms
コンパイル使用メモリ 207,804 KB
実行使用メモリ 20,588 KB
最終ジャッジ日時 2024-04-20 13:40:39
合計ジャッジ時間 5,983 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 71 ms
13,504 KB
testcase_03 AC 148 ms
17,484 KB
testcase_04 AC 71 ms
13,184 KB
testcase_05 AC 99 ms
13,056 KB
testcase_06 AC 125 ms
15,952 KB
testcase_07 AC 209 ms
20,012 KB
testcase_08 AC 173 ms
20,164 KB
testcase_09 AC 188 ms
20,308 KB
testcase_10 AC 144 ms
19,628 KB
testcase_11 AC 173 ms
20,256 KB
testcase_12 AC 132 ms
18,828 KB
testcase_13 AC 125 ms
18,868 KB
testcase_14 AC 145 ms
18,828 KB
testcase_15 AC 101 ms
17,932 KB
testcase_16 AC 103 ms
16,952 KB
testcase_17 AC 182 ms
20,448 KB
testcase_18 AC 166 ms
20,588 KB
testcase_19 AC 118 ms
17,800 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

constexpr ll mod = 998244353;

template<ll mod>
struct Mint {
  using M=Mint; ll v;
  M& put(ll x) { v=(x<mod)?x:x-mod; return *this; }
  Mint(ll x=0) { put(x%mod+mod); }
  M operator+(M m) {return M().put(v+m.v);}
  M operator-(M m) {return M().put(v+mod-m.v);}
  M operator*(M m) {return M().put(v*m.v%mod);}
  M operator/(M m) {return M().put(v*m.inv().v%mod);}
// BEGIN IGNORE
  M operator+=(M m) { return put(v+m.v); }
  M operator-=(M m) { return put(v+mod-m.v); }
  M operator*=(M m) { return put(v*m.v%mod); }
  M operator/=(M m) { return put(v*m.inv().v%mod); }
// END IGNORE
  bool operator==(M m) { return v==m.v; }
  M pow(ll m) const {
    M x=v, res=1;
    while (m) {
      if (m&1) res=res*x;
      x=x*x; m>>=1;
    }
    return res;
  }
  M inv() { return pow(mod-2); }
};

using mint = Mint<mod>;


int main(){

  cin.tie(0);
  cin.sync_with_stdio(0);

  int n, m, x;
  cin >> n >> m >> x;
  vector<vector<pair<ll,ll>>> edges(n);
  for(int i = 0; i < m; ++i){
    int u, v, c, t;
    cin >> u >> v >> c >> t;
    --u, --v;
    edges[u].emplace_back(v, c + 1ll * t * x);
    edges[v].emplace_back(u, c + 1ll * t * x);
  }
  vector<ll> dp(n, 1e18);
  dp[0] = 0;
  priority_queue<pair<ll,int>, vector<pair<ll,int>>, greater<>> que;
  que.emplace(0, 0);
  while(!que.empty()){
    auto [d, pos] = que.top();
    que.pop();
    if(dp[pos] != d)continue;
    for(auto [to, cos] : edges[pos]){
      if(dp[to] > d + cos){
        dp[to] = d + cos;
        que.emplace(d + cos, to);
      }
    }
  }
  if(dp.back() == 1e18){
    cout << -1 << endl;
  }
  else{
    cout << (dp.back() + x - 1) / x << endl;
  }
}
0