結果

問題 No.2387 Yokan Factory
ユーザー Ricky_ponRicky_pon
提出日時 2023-07-21 21:32:51
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 5,870 bytes
コンパイル時間 1,726 ms
コンパイル使用メモリ 155,800 KB
実行使用メモリ 13,984 KB
最終ジャッジ日時 2023-10-21 21:23:57
合計ジャッジ時間 8,047 ms
ジャッジサーバーID
(参考情報)
judge9 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 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 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 421 ms
13,836 KB
testcase_16 AC 296 ms
12,228 KB
testcase_17 AC 571 ms
13,984 KB
testcase_18 RE -
testcase_19 RE -
testcase_20 AC 417 ms
9,000 KB
testcase_21 AC 1,035 ms
13,044 KB
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 AC 817 ms
11,468 KB
testcase_27 RE -
testcase_28 AC 5 ms
4,348 KB
testcase_29 AC 7 ms
4,348 KB
testcase_30 AC 6 ms
4,348 KB
testcase_31 AC 5 ms
4,348 KB
testcase_32 AC 4 ms
4,348 KB
testcase_33 AC 3 ms
4,348 KB
testcase_34 AC 7 ms
4,348 KB
testcase_35 AC 6 ms
4,348 KB
testcase_36 AC 4 ms
4,348 KB
testcase_37 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <string.h>

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <chrono>
#include <ciso646>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <optional>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP_OVERLOAD(arg1, arg2, arg3, arg4, NAME, ...) NAME
#define REP3(i, l, r, s)                                               \
    for (int i = int(l), rep3_r = int(r), rep3_s = int(s); i < rep3_r; \
         i += rep3_s)
#define REP2(i, l, r) REP3(i, l, r, 1)
#define REP1(i, n) REP2(i, 0, n)
#define rep(...) REP_OVERLOAD(__VA_ARGS__, REP3, REP2, REP1, )(__VA_ARGS__)
#define repin(i, l, r) for (int i = int(l), repin_r = int(r); i <= repin_r; ++i)

#define RREP_OVERLOAD(arg1, arg2, arg3, arg4, NAME, ...) NAME
#define RREP3(i, l, r, s)                                                      \
    for (int i = int(r) - 1, rrep3_l = int(l), rrep3_s = int(s); i >= rrep3_l; \
         i -= rrep3_s)
#define RREP2(i, l, r) RREP3(i, l, r, 1)
#define RREP1(i, n) RREP2(i, 0, n)
#define rrep(...) RREP_OVERLOAD(__VA_ARGS__, RREP3, RREP2, RREP1, )(__VA_ARGS__)
#define rrepin(i, l, r) \
    for (int i = int(r), rrepin_l = int(l); i >= rrepin_l; --i)

#define all(v) v.begin(), v.end()


#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>

namespace rklib {

template <class T>
std::ostream &operator<<(std::ostream &os, const std::vector<T> &v) {
    os << "[";
    for (auto d : v) os << d << ", ";
    return os << "]";
}

// a <- max(a, b)
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

// a <- min(a, b)
template <class T>
bool chmin(T &a, const T &b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

// if a < 0: a <- b
// else: a <- min(a, b)
template <class T>
bool chmin_non_negative(T &a, const T &b) {
    if (a < 0 || a > b) {
        a = b;
        return true;
    }
    return false;
}

// floor(num / den)
template <class T>
T div_floor(T num, T den) {
    if (den < 0) num = -num, den = -den;
    return num >= 0 ? num / den : (num + 1) / den - 1;
}

// ceil(num / den)
template <class T>
T div_ceil(T num, T den) {
    if (den < 0) num = -num, den = -den;
    return num <= 0 ? num / den : (num - 1) / den + 1;
}

}  // namespace rklib


using namespace std;
using namespace rklib;

using lint = long long;
using ulint = unsigned long long;
using pii = pair<int, int>;
using pll = pair<lint, lint>;
template <class T>
using vec = vector<T>;
template <class T>
using vvec = vec<vec<T>>;
template <class T>
using vvvec = vec<vvec<T>>;


#include <limits>
#include <queue>

#include <vector>

namespace rklib {

template <class T = int>
struct Edge {
    int from, to;
    T cost;
    int idx;

    Edge() = default;

    Edge(int from, int to, T cost = 1, int idx = 0)
        : from(from), to(to), cost(cost), idx(idx) {}
};

template <class T = int>
struct Graph {
    std::vector<std::vector<Edge<T>>> es;
    int edge_num;

    Graph(int n) : edge_num(0) { es.resize(n); }

    int size() { return es.size(); }

    void add_edge(int from, int to, T cost, int idx) {
        es[from].emplace_back(from, to, cost, idx);
        ++edge_num;
    }

    std::vector<Edge<T>> edges() {
        std::vector<Edge<T>> res(edge_num);
        for (int v = 0; v < (int)es.size(); ++v) {
            for (auto& e : es[v]) {
                res[e.idx] = e;
            }
        }
        return res;
    }

    std::vector<Edge<T>>& operator[](int i) { return es[i]; }
};

}  // namespace rklib

#include <vector>

namespace rklib {

template <class T>
std::pair<std::vector<T>, std::vector<int>> dijkstra(Graph<T> &gr, int s) {
    constexpr auto INF = std::numeric_limits<T>::max();
    std::vector<T> dist(gr.size(), INF);
    std::vector<int> pre(gr.size(), -1);
    std::priority_queue<std::pair<T, int>, std::vector<std::pair<T, int>>,
                        std::greater<std::pair<T, int>>>
        que;
    que.emplace(0, s);
    dist[s] = 0;
    while (!que.empty()) {
        auto [d, v] = que.top();
        que.pop();
        if (d > dist[v]) continue;
        for (auto &e : gr[v])
            if (chmin(dist[e.to], dist[v] + e.cost)) {
                que.emplace(dist[e.to], e.to);
                pre[e.to] = e.idx;
            }
    }
    return {dist, pre};
}

template <class T>
std::pair<T, std::vector<int>> dijkstra(Graph<T> &gr, int s, int t) {
    auto [dist, pre] = dijkstra(gr, s);
    std::vector<int> res;
    auto es = gr.edges();
    for (int e = pre[t]; e >= 0; e = pre[es[e].from]) {
        res.push_back(e);
    }
    reverse(res.begin(), res.end());
    return {dist[t], res};
}

}  // namespace rklib


int main() {
    int n, m, x;
    cin >> n >> m >> x;
    vec<pair<pii, pii>> es;
    rep(i, m) {
        int u, v, a, b;
        cin >> u >> v >> a >> b;
        --u;
        --v;
        es.push_back(make_pair(make_pair(u, v), make_pair(a, b)));
    }

    int low = -1, high = 1'000'000'010;
    while (high - low > 1) {
        int mid = (high + low) / 2;

        Graph<lint> gr(n);
        int cur = 0;
        for (auto [p, q] : es) {
            if (q.second < mid) continue;
            gr.add_edge(p.first, p.second, q.first, cur);
            ++cur;
            gr.add_edge(p.second, p.first, q.first, cur);
            ++cur;
        }

        auto ds = dijkstra(gr, 0).first;
        if (ds[n - 1] <= x) {
            low = mid;
        } else {
            high = mid;
        }
    }
    cout << low << endl;
}
0