結果

問題 No.2739 Time is money
コンテスト
ユーザー a01sa01to
提出日時 2026-02-09 00:25:25
言語 C++23
(gcc 15.2.0 + boost 1.89.0)
結果
AC  
実行時間 257 ms / 2,000 ms
コード長 991 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 7,581 ms
コンパイル使用メモリ 349,072 KB
実行使用メモリ 20,524 KB
最終ジャッジ日時 2026-02-09 00:25:41
合計ジャッジ時間 14,513 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
using ll = long long;
using ull = unsigned long long;

int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  ll n, m, x;
  cin >> n >> m >> x;
  vector Graph(n, vector<pair<int, ll>>(0));
  rep(_, m) {
    int u, v, c, t;
    cin >> u >> v >> c >> t;
    --u, --v;
    Graph[u].push_back({ v, c + t * x });
    Graph[v].push_back({ u, c + t * x });
  }
  priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<>> pq;
  constexpr ll INF = 1e18;
  vector<ll> dist(n, INF);
  pq.push({ 0, 0 });
  dist[0] = 0;
  while (!pq.empty()) {
    auto [d, v] = pq.top();
    pq.pop();
    if (dist[v] < d) continue;
    for (auto [u, c] : Graph[v]) {
      if (dist[u] > dist[v] + c) {
        dist[u] = dist[v] + c;
        pq.push({ dist[u], u });
      }
    }
  }
  if (dist[n - 1] == INF) {
    cout << -1 << '\n';
  }
  else {
    cout << (dist[n - 1] + x - 1) / x << '\n';
  }
  return 0;
}
0