結果

問題 No.2739 Time is money
ユーザー KudeKude
提出日時 2024-04-21 10:05:38
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 173 ms / 2,000 ms
コード長 1,795 bytes
コンパイル時間 3,692 ms
コンパイル使用メモリ 306,672 KB
実行使用メモリ 20,572 KB
最終ジャッジ日時 2024-04-21 10:05:48
合計ジャッジ時間 8,606 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 69 ms
13,484 KB
testcase_03 AC 136 ms
17,564 KB
testcase_04 AC 66 ms
12,924 KB
testcase_05 AC 95 ms
13,056 KB
testcase_06 AC 126 ms
15,828 KB
testcase_07 AC 168 ms
19,840 KB
testcase_08 AC 163 ms
20,096 KB
testcase_09 AC 173 ms
20,260 KB
testcase_10 AC 135 ms
19,556 KB
testcase_11 AC 162 ms
20,224 KB
testcase_12 AC 126 ms
18,692 KB
testcase_13 AC 121 ms
18,812 KB
testcase_14 AC 115 ms
18,804 KB
testcase_15 AC 97 ms
17,932 KB
testcase_16 AC 97 ms
16,948 KB
testcase_17 AC 151 ms
20,572 KB
testcase_18 AC 159 ms
20,480 KB
testcase_19 AC 111 ms
17,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
namespace {
#pragma GCC diagnostic ignored "-Wunused-function"
#include<atcoder/all>
#pragma GCC diagnostic warning "-Wunused-function"
using namespace std;
using namespace atcoder;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; }
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;

constexpr long long INF = 1002003004005006007;
vector<long long> dijkstra(const auto& to, int s = 0) {
  struct QueElem {
    int v;
    long long d;
    bool operator<(const QueElem& a) const { return d > a.d; }
    QueElem(int v, long long d) : v(v), d(d) {}
  };
  priority_queue<QueElem> q;
  vector<long long> dist(to.size(), INF);
  dist[s] = 0;
  q.emplace(s, 0);
  while (!q.empty()) {
    auto [u, d] = q.top(); q.pop();
    if (d > dist[u]) continue;
    for (auto [v, dv] : to[u]) {
      long long nd = d + dv;
      if (nd < dist[v]) {
        dist[v] = nd;
        q.emplace(v, nd);
      }
    }
  }
  return dist;
}

} int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m, x;
  cin >> n >> m >> x;
  vector<vector<pair<int, ll>>> to(n);
  rep(_, m) {
    int u, v, c, t;
    cin >> u >> v >> c >> t;
    u--, v--;
    ll cost = c + (ll)x * t;
    to[u].emplace_back(v, cost);
    to[v].emplace_back(u, cost);
  }
  ll ans = dijkstra(to).back();
  if (ans == INF) ans = -1;
  else ans = (ans + x - 1) / x;
  cout << ans << '\n';
}
0