結果

問題 No.2387 Yokan Factory
ユーザー simansiman
提出日時 2023-07-23 18:39:50
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 581 ms / 5,000 ms
コード長 1,630 bytes
コンパイル時間 1,194 ms
コンパイル使用メモリ 132,632 KB
実行使用メモリ 15,084 KB
最終ジャッジ日時 2023-10-25 01:14:57
合計ジャッジ時間 7,948 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 1 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 1 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 271 ms
13,772 KB
testcase_16 AC 156 ms
13,284 KB
testcase_17 AC 462 ms
15,084 KB
testcase_18 AC 538 ms
13,180 KB
testcase_19 AC 219 ms
11,012 KB
testcase_20 AC 136 ms
9,400 KB
testcase_21 AC 444 ms
12,244 KB
testcase_22 AC 128 ms
8,872 KB
testcase_23 AC 581 ms
10,888 KB
testcase_24 AC 180 ms
9,692 KB
testcase_25 AC 157 ms
7,220 KB
testcase_26 AC 241 ms
10,716 KB
testcase_27 AC 184 ms
11,196 KB
testcase_28 AC 3 ms
4,348 KB
testcase_29 AC 3 ms
4,348 KB
testcase_30 AC 3 ms
4,348 KB
testcase_31 AC 3 ms
4,348 KB
testcase_32 AC 2 ms
4,348 KB
testcase_33 AC 2 ms
4,348 KB
testcase_34 AC 4 ms
4,348 KB
testcase_35 AC 4 ms
4,348 KB
testcase_36 AC 2 ms
4,348 KB
testcase_37 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <climits>
#include <map>
#include <queue>
#include <set>
#include <cstring>
#include <vector>

using namespace std;
typedef long long ll;

struct Edge {
  ll u;
  ll v;
  ll a;
  ll b;
};

struct Node {
  int u;
  ll time;

  Node(int u = -1, ll time = -1) {
    this->u = u;
    this->time = time;;
  }

  bool operator>(const Node &n) const {
    return time > n.time;
  }
};

int main() {
  ll N, M, X;
  cin >> N >> M >> X;

  vector<Edge> G[N + 1];

  for (int i = 0; i < M; ++i) {
    ll u, v, a, b;
    cin >> u >> v >> a >> b;

    G[u].push_back(Edge{
        .u = u,
        .v = v,
        .a = a,
        .b = b,
    });
    G[v].push_back(Edge{
        .u = v,
        .v = u,
        .a = a,
        .b = b,
    });
  }

  ll ok = -1;
  ll ng = 1000000000;

  while (abs(ok - ng) >= 2) {
    ll size = (ok + ng) / 2;
    bool visited[N + 1];
    memset(visited, false, sizeof(visited));
    priority_queue <Node, vector<Node>, greater<Node>> pque;
    pque.push(Node(1, 0));
    bool success = false;

    while (not pque.empty()) {
      Node node = pque.top();
      pque.pop();

      if (visited[node.u]) continue;
      visited[node.u] = true;

      if (node.u == N) {
        success = true;
        break;
      }

      for (Edge &e : G[node.u]) {
        if (e.b < size) continue;
        if (e.a + node.time > X) continue;

        pque.push(Node(e.v, node.time + e.a));
      }
    }

    if (success) {
      ok = size;
    } else {
      ng = size;
    }
  }

  cout << ok << endl;

  return 0;
}
0