結果
問題 | No.2387 Yokan Factory |
ユーザー |
![]() |
提出日時 | 2025-02-06 14:02:30 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 843 ms / 5,000 ms |
コード長 | 1,881 bytes |
コンパイル時間 | 4,673 ms |
コンパイル使用メモリ | 289,236 KB |
実行使用メモリ | 12,292 KB |
最終ジャッジ日時 | 2025-02-06 14:02:49 |
合計ジャッジ時間 | 14,518 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 35 |
ソースコード
#include <bits/stdc++.h>using namespace std;using ll = long long;#ifdef LOCAL#include <debug.hpp>#else#define debug(...)#endif// 到達不可: -1template <class T>vector<T> dijkstra(const vector<vector<pair<int, T>>>& G, int start = 0) {int N = G.size();vector<T> dist(N, T(-1));priority_queue<pair<T, int>, vector<pair<T, int>>, greater<pair<T, int>>> que;dist[start] = 0;que.emplace(dist[start], start);while (!que.empty()) {auto [expected, from] = que.top();que.pop();// 最短距離でない場合, continueif (dist[from] < expected) continue;for (auto&& [to, cost] : G[from]) {if (dist[to] == T(-1) || dist[to] > dist[from] + cost) {dist[to] = dist[from] + cost;que.emplace(dist[to], to);}}}return dist;}int main() {cin.tie(nullptr);ios::sync_with_stdio(false);cout << fixed << setprecision(20);ll N, M, X;cin >> N >> M >> X;vector<int> U(M), V(M), A(M), B(M);for (int i = 0; i < M; i++) {cin >> U[i] >> V[i] >> A[i] >> B[i], U[i]--, V[i]--;}// 大きさ mid のようかんを運送できるかauto check = [&](int mid) -> bool {// 幅 mid 以上の辺のみを用いたグラフを構築vector<vector<pair<int, ll>>> G(N);for (int i = 0; i < M; i++) {if (B[i] < mid) continue;G[U[i]].emplace_back(V[i], A[i]);G[V[i]].emplace_back(U[i], A[i]);}// グラフ G の 0 -> N までの最短経路を求めるauto dist = dijkstra(G);return dist[N - 1] != -1 && dist[N - 1] <= X;};int ok = -1, ng = 1e9 + 1;while (ng - ok > 1) {int mid = midpoint(ok, ng);(check(mid) ? ok : ng) = mid;}cout << ok << '\n';}