結果
問題 | No.2739 Time is money |
ユーザー |
![]() |
提出日時 | 2024-04-30 19:12:25 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 264 ms / 2,000 ms |
コード長 | 1,211 bytes |
コンパイル時間 | 615 ms |
コンパイル使用メモリ | 64,316 KB |
最終ジャッジ日時 | 2025-02-21 09:55:01 |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 18 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:37:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 37 | scanf("%d%d%d", &n, &m, &x); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~ main.cpp:41:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 41 | scanf("%d%d%d%d", &u, &v, &c, &t); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
/* -*- coding: utf-8 -*- * * 2739.cc: No.2739 Time is money - yukicoder */ #include<cstdio> #include<vector> #include<queue> #include<algorithm> #include<utility> using namespace std; /* constant */ const int MAX_N = 200000; const long long LINF = 1LL << 62; /* typedef */ typedef long long ll; typedef pair<int,ll> pil; typedef pair<ll,int> pli; typedef vector<pil> vpil; /* global variables */ vpil nbrs[MAX_N]; ll ds[MAX_N]; /* subroutines */ /* main */ int main() { int n, m, x; scanf("%d%d%d", &n, &m, &x); for (int i = 0; i < m; i++) { int u, v, c, t; scanf("%d%d%d%d", &u, &v, &c, &t); u--, v--; ll w = (ll)t * x + c; nbrs[u].push_back({v, w}); nbrs[v].push_back({u, w}); } fill(ds, ds + n, LINF); ds[0] = 0; priority_queue<pli> q; q.push({0, 0}); while (! q.empty()) { auto [ud, u] = q.top(); q.pop(); ud = -ud; if (ds[u] != ud) continue; if (u == n - 1) break; for (auto [v, w]: nbrs[u]) { ll vd = ud + w; if (ds[v] > vd) { ds[v] = vd; q.push({-vd, v}); } } } if (ds[n - 1] >= LINF) puts("-1"); else { ll gt = (ds[n - 1] + x - 1) / x; printf("%lld\n", gt); } return 0; }