結果

問題 No.2387 Yokan Factory
コンテスト
ユーザー siman
提出日時 2023-07-23 12:22:37
言語 C++17(clang)
(clang++ 22.1.2 + boost 1.89.0)
コンパイル:
clang++ -O2 -lm -std=c++1z -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 1,646 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,338 ms
コンパイル使用メモリ 152,320 KB
実行使用メモリ 14,192 KB
最終ジャッジ日時 2026-04-11 16:50:11
合計ジャッジ時間 6,973 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 32 WA * 3
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:41:18: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
   41 |   vector<Edge> G[N + 1];
      |                  ^~~~~
main.cpp:41:18: note: read of non-const variable 'N' is not allowed in a constant expression
main.cpp:38:6: note: declared here
   38 |   ll N, M, X;
      |      ^
main.cpp:66:18: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
   66 |     bool visited[N + 1];
      |                  ^~~~~
main.cpp:66:18: note: read of non-const variable 'N' is not allowed in a constant expression
main.cpp:38:6: note: declared here
   38 |   ll N, M, X;
      |      ^
2 warnings generated.

ソースコード

diff #
raw source code

#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 id;
  int cnt;

  Node(int id = -1, int cnt = -1) {
    this->id = id;
    this->cnt = cnt;
  }

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

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));
    queue<int> que;
    queue<ll> t_que;
    que.push(1);
    t_que.push(0);
    bool success = false;

    while (not que.empty()) {
      int u = que.front();
      ll time = t_que.front();
      que.pop();
      t_que.pop();

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

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

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

        que.push(e.v);
        t_que.push(time + e.a);
      }
    }

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

  cout << ok << endl;

  return 0;
}
0