結果

問題 No.2387 Yokan Factory
ユーザー tnakao0123tnakao0123
提出日時 2023-07-25 11:20:47
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 262 ms / 5,000 ms
コード長 1,535 bytes
コンパイル時間 596 ms
コンパイル使用メモリ 61,804 KB
実行使用メモリ 11,320 KB
最終ジャッジ日時 2024-04-10 04:17:11
合計ジャッジ時間 4,553 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 3 ms
6,984 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 3 ms
7,360 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 3 ms
6,980 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 3 ms
6,940 KB
testcase_12 AC 3 ms
6,944 KB
testcase_13 AC 2 ms
6,940 KB
testcase_14 AC 2 ms
6,944 KB
testcase_15 AC 170 ms
10,808 KB
testcase_16 AC 72 ms
11,320 KB
testcase_17 AC 262 ms
10,924 KB
testcase_18 AC 183 ms
10,408 KB
testcase_19 AC 161 ms
8,908 KB
testcase_20 AC 116 ms
9,180 KB
testcase_21 AC 247 ms
9,796 KB
testcase_22 AC 91 ms
9,240 KB
testcase_23 AC 233 ms
8,856 KB
testcase_24 AC 110 ms
8,524 KB
testcase_25 AC 24 ms
7,764 KB
testcase_26 AC 47 ms
9,728 KB
testcase_27 AC 47 ms
9,812 KB
testcase_28 AC 3 ms
6,944 KB
testcase_29 AC 4 ms
6,940 KB
testcase_30 AC 4 ms
6,948 KB
testcase_31 AC 3 ms
6,944 KB
testcase_32 AC 3 ms
6,944 KB
testcase_33 AC 3 ms
6,940 KB
testcase_34 AC 4 ms
6,944 KB
testcase_35 AC 3 ms
6,944 KB
testcase_36 AC 3 ms
6,944 KB
testcase_37 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 2387.cc:  No.2387 Yokan Factory - yukicoder
 */

#include<cstdio>
#include<vector>
#include<queue>
#include<algorithm>
#include<utility>
 
using namespace std;

/* constant */

const int MAX_N = 100000;
const int MAX_M = 100000;
const long long LINF = 1LL << 62;

/* typedef */

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<pii> vpii;
typedef pair<ll,int> pli;

/* global variables */

vpii nbrs[MAX_N];
int as[MAX_M], bs[MAX_M];
ll ds[MAX_N];

/* subroutines */

ll dijkstra(int n, int b) {
  fill(ds, ds + n, LINF);
  ds[0] = 0;
  priority_queue<pli> q;
  q.push(pli(0, 0));

  while (! q.empty()) {
    auto ue = q.top(); q.pop();
    ll ud = -ue.first;
    int u = ue.second;
    if (ds[u] != ud) continue;
    if (u == n - 1) break;

    for (auto ve: nbrs[u]) {
      int v = ve.first, ei = ve.second;
      if (bs[ei] >= b) {
	ll vd = ud + as[ei];
	if (ds[v] > vd) {
	  ds[v] = vd;
	  q.push(pli(-vd, v));
	}
      }
    }
  }

  return ds[n - 1];
}

/* main */

int main() {
  int n, m;
  ll x;
  scanf("%d%d%lld", &n, &m, &x);

  for (int i = 0; i < m; i++) {
    int u, v;
    scanf("%d%d%d%d", &u, &v, as + i, bs + i);
    u--, v--;
    nbrs[u].push_back(pii(v, i));
    nbrs[v].push_back(pii(u, i));
  }

  if (dijkstra(n, 1) > x) { puts("-1"); return 0; }

  int maxb = *max_element(bs, bs + m);
  int b0 = 1, b1 = maxb + 1;

  while (b0 + 1 < b1) {
    int b = (b0 + b1) / 2;
    if (dijkstra(n, b) > x) b1 = b;
    else b0 = b;
  }

  printf("%d\n", b0);

  return 0;
}
0