結果

問題 No.2739 Time is money
ユーザー tnakao0123tnakao0123
提出日時 2024-04-30 19:12:25
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 178 ms / 2,000 ms
コード長 1,211 bytes
コンパイル時間 628 ms
コンパイル使用メモリ 63,360 KB
実行使用メモリ 20,788 KB
最終ジャッジ日時 2024-04-30 19:12:31
合計ジャッジ時間 5,718 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
8,128 KB
testcase_01 AC 2 ms
7,784 KB
testcase_02 AC 66 ms
15,172 KB
testcase_03 AC 107 ms
18,900 KB
testcase_04 AC 60 ms
15,164 KB
testcase_05 AC 75 ms
15,464 KB
testcase_06 AC 113 ms
18,628 KB
testcase_07 AC 151 ms
19,788 KB
testcase_08 AC 150 ms
19,648 KB
testcase_09 AC 129 ms
19,900 KB
testcase_10 AC 125 ms
19,392 KB
testcase_11 AC 156 ms
19,872 KB
testcase_12 AC 130 ms
18,732 KB
testcase_13 AC 128 ms
18,648 KB
testcase_14 AC 118 ms
18,752 KB
testcase_15 AC 101 ms
20,788 KB
testcase_16 AC 77 ms
17,596 KB
testcase_17 AC 178 ms
20,212 KB
testcase_18 AC 154 ms
20,096 KB
testcase_19 AC 91 ms
19,632 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- 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;
}
0