結果
| 問題 | No.2739 Time is money |
| コンテスト | |
| ユーザー |
tnakao0123
|
| 提出日時 | 2024-04-30 19:12:25 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.90.0) |
| 結果 |
AC
|
| 実行時間 | 153 ms / 2,000 ms |
| コード長 | 1,211 bytes |
| 記録 | |
| コンパイル時間 | 550 ms |
| コンパイル使用メモリ | 77,604 KB |
| 実行使用メモリ | 21,040 KB |
| 最終ジャッジ日時 | 2026-07-04 15:57:54 |
| 合計ジャッジ時間 | 6,383 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 18 |
ソースコード
/* -*- 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;
}
tnakao0123