結果

問題 No.2387 Yokan Factory
ユーザー 👑 emthrm
提出日時 2023-07-21 21:33:00
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 979 ms / 5,000 ms
コード長 3,161 bytes
コンパイル時間 3,558 ms
コンパイル使用メモリ 271,232 KB
実行使用メモリ 17,972 KB
最終ジャッジ日時 2024-09-21 22:52:02
合計ジャッジ時間 12,565 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 35
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr double EPS = 1e-8;
constexpr int MOD = 998244353;
// constexpr int MOD = 1000000007;
constexpr int DY4[]{1, 0, -1, 0}, DX4[]{0, -1, 0, 1};
constexpr int DY8[]{1, 1, 0, -1, -1, -1, 0, 1};
constexpr int DX8[]{0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U>
inline bool chmax(T& a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U>
inline bool chmin(T& a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
IOSetup() {
std::cin.tie(nullptr);
std::ios_base::sync_with_stdio(false);
std::cout << fixed << setprecision(20);
}
} iosetup;
template <typename CostType>
struct Edge {
CostType cost;
int src, dst;
explicit Edge(const int src, const int dst, const CostType cost = 0)
: cost(cost), src(src), dst(dst) {}
auto operator<=>(const Edge& x) const = default;
};
template <typename CostType>
struct Dijkstra {
const CostType inf;
Dijkstra(const std::vector<std::vector<Edge<CostType>>>& graph,
const CostType inf = std::numeric_limits<CostType>::max())
: inf(inf), is_built(false), graph(graph) {}
std::vector<CostType> build(const int s) {
is_built = true;
const int n = graph.size();
std::vector<CostType> dist(n, inf);
dist[s] = 0;
prev.assign(n, -1);
std::priority_queue<std::pair<CostType, int>,
std::vector<std::pair<CostType, int>>,
std::greater<std::pair<CostType, int>>> que;
que.emplace(0, s);
while (!que.empty()) {
const auto [d, ver] = que.top();
que.pop();
if (d > dist[ver]) continue;
for (const Edge<CostType>& e : graph[ver]) {
if (dist[ver] + e.cost < dist[e.dst]) {
dist[e.dst] = dist[ver] + e.cost;
prev[e.dst] = ver;
que.emplace(dist[e.dst], e.dst);
}
}
}
return dist;
}
std::vector<int> build_path(int t) const {
assert(is_built);
std::vector<int> res;
for (; t != -1; t = prev[t]) {
res.emplace_back(t);
}
std::reverse(res.begin(), res.end());
return res;
}
private:
bool is_built;
std::vector<int> prev;
std::vector<std::vector<Edge<CostType>>> graph;
};
int main() {
int n, m; ll x; cin >> n >> m >> x;
vector<int> u(m), v(m), a(m), b(m); REP(i, m) cin >> u[i] >> v[i] >> a[i] >> b[i], --u[i], --v[i];
vector<int> order(m);
iota(ALL(order), 0);
ranges::sort(order, greater<int>(), [&](const int i) -> int { return b[i]; });
int lb = -1, ub = b[order.front()] + 1;
while (ub - lb > 1) {
const int mid = midpoint(lb, ub);
vector<vector<Edge<ll>>> graph(n);
for (const int i : order) {
if (b[i] < mid) break;
graph[u[i]].emplace_back(u[i], v[i], a[i]);
graph[v[i]].emplace_back(v[i], u[i], a[i]);
}
(Dijkstra(graph).build(0)[n - 1] <= x ? lb : ub) = mid;
}
cout << lb << '\n';
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0