結果

問題 No.2387 Yokan Factory
ユーザー cleanttedcleantted
提出日時 2023-06-14 15:38:37
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 390 ms / 5,000 ms
コード長 1,392 bytes
コンパイル時間 1,584 ms
コンパイル使用メモリ 97,208 KB
実行使用メモリ 12,080 KB
最終ジャッジ日時 2023-09-06 01:20:55
合計ジャッジ時間 5,616 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 235 ms
12,080 KB
testcase_16 AC 147 ms
11,880 KB
testcase_17 AC 320 ms
11,820 KB
testcase_18 AC 390 ms
10,900 KB
testcase_19 AC 187 ms
8,752 KB
testcase_20 AC 122 ms
8,384 KB
testcase_21 AC 360 ms
10,436 KB
testcase_22 AC 115 ms
7,808 KB
testcase_23 AC 335 ms
8,880 KB
testcase_24 AC 130 ms
8,028 KB
testcase_25 AC 130 ms
6,284 KB
testcase_26 AC 214 ms
9,592 KB
testcase_27 AC 157 ms
9,988 KB
testcase_28 AC 3 ms
4,380 KB
testcase_29 AC 3 ms
4,380 KB
testcase_30 AC 3 ms
4,376 KB
testcase_31 AC 3 ms
4,380 KB
testcase_32 AC 3 ms
4,380 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 3 ms
4,380 KB
testcase_35 AC 4 ms
4,380 KB
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:49:18: 警告: ‘i’ may be used uninitialized [-Wmaybe-uninitialized]
   49 |     for (ll i; i < M; ++i) {
      |                ~~^~~
main.cpp:49:13: 備考: ‘i’ はここで定義されています
   49 |     for (ll i; i < M; ++i) {
      |             ^

ソースコード

diff #

#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <tuple>
using namespace std;
using ll = long long;

bool f(const vector<vector<tuple<ll, ll, ll>>>& G, ll N, ll X, ll m) {
    priority_queue<tuple<ll, ll>> S;
    vector<bool> fixed(N, false);
    vector<ll> D(N, X + 1);
    D[0] = 0;
    S.push(make_tuple(0, 0));
    while (!S.empty()) {
      auto [c, i] = S.top();
      c = -c;
      S.pop();
      if (i == N - 1) {
        break;
      }
      if (fixed[i]) {
        continue;
      }
      fixed[i] = true;
      for (auto& [j, a, b] : G[i]) {
        if (m > b) {
          continue;
        }
        if (D[j] <= c + a) {
          continue;
        }
        if (c + a > X) {
          continue;
        }
        D[j] = c + a;
        S.push(make_tuple(-(c + a), j));
      }
    }
    return D[N - 1] <= X;
}

int main() {
    ll N, M, X;
    cin >> N >> M >> X;
    
    ll u, v, a, b;
    vector<vector<tuple<ll, ll, ll>>> G(N);
    for (ll i; i < M; ++i) {
      cin >> u >> v >> a >> b;
      --u;
      --v;
      G[u].push_back(make_tuple(v, a, b));
      G[v].push_back(make_tuple(u, a, b));
    }
    
    ll l = -1;
    ll r = 1e9 + 10;
    while (r - l > 1) {
        ll m = (l + r) / 2;
        if (f(G, N, X, m)) {
            l = m;
        } else {
            r = m;
        }
    }

    cout << l << endl;
    
    return 0;
}
0