結果

問題 No.2387 Yokan Factory
ユーザー kobaryo222kobaryo222
提出日時 2023-07-21 21:34:58
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 563 ms / 5,000 ms
コード長 4,401 bytes
コンパイル時間 2,529 ms
コンパイル使用メモリ 219,140 KB
実行使用メモリ 15,448 KB
最終ジャッジ日時 2023-10-21 21:26:38
合計ジャッジ時間 7,773 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 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 193 ms
15,448 KB
testcase_16 AC 102 ms
13,904 KB
testcase_17 AC 286 ms
14,060 KB
testcase_18 AC 419 ms
14,232 KB
testcase_19 AC 322 ms
10,820 KB
testcase_20 AC 255 ms
10,016 KB
testcase_21 AC 563 ms
13,280 KB
testcase_22 AC 225 ms
9,404 KB
testcase_23 AC 348 ms
10,820 KB
testcase_24 AC 126 ms
9,756 KB
testcase_25 AC 176 ms
7,696 KB
testcase_26 AC 407 ms
11,828 KB
testcase_27 AC 506 ms
12,780 KB
testcase_28 AC 3 ms
4,348 KB
testcase_29 AC 4 ms
4,348 KB
testcase_30 AC 4 ms
4,348 KB
testcase_31 AC 3 ms
4,348 KB
testcase_32 AC 3 ms
4,348 KB
testcase_33 AC 2 ms
4,348 KB
testcase_34 AC 4 ms
4,348 KB
testcase_35 AC 3 ms
4,348 KB
testcase_36 AC 2 ms
4,348 KB
testcase_37 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using pl = pair<ll, ll>;
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvvl vector<vector<vector<ll>>>
#define vm vector<mint>
#define vvm vector<vector<mint>>
#define vvvm vector<vector<vector<mint>>>
#define vp vector<pl>
#define vvp vector<vector<pl>>
#define vs vector<string>
#define vvs vector<vector<string>>

#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(ll i = ll(a); i < ll(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(x) std::begin(x), std::end(x)
#define make_unique(v) v.erase(unique(all(v)), v.end());
#define sum(...) accumulate(all(__VA_ARGS__), 0LL)
#define inf (0x1fffffffffffffffLL)

template <class T>
istream &operator>>(istream &is, vector<T> &v) {
    for(auto &x : v) {
        is >> x;
    }
    return is;
}

template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    for(int i = 0; i < (int)v.size(); i++) {
        if(i != (int)v.size() - 1)
            os << v[i] << " ";
        else
            os << v[i];
    }
    return os;
}

template <typename T, typename... Args>
auto make_v(T x, int arg, Args... args) {
    if constexpr(sizeof...(args) == 0)
        return vector<T>(arg, x);
    else
        return vector(arg, make_v<T>(x, args...));
}

template <class T>
auto min(const T &a) {
    return *min_element(all(a));
}

template <class T>
auto max(const T &a) {
    return *max_element(all(a));
}

template <class T>
bool chmin(T &a, const T &b) {
    return a > b ? a = b, true : false;
}

template <class T>
bool chmax(T &a, const T &b) {
    return a < b ? a = b, true : false;
}

struct IoSetup {
    IoSetup() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
        cerr << fixed << setprecision(10);
    }
} iosetup;

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

    Edge() = default;

    Edge(int from, int to, T cost = 1, T b = 1, int idx = -1)
      : from(from)
      , to(to)
      , cost(cost)
      , b(b)
      , idx(idx) {
    }

    operator int() const { return to; }
};

template <typename T = int>
struct Graph {
    vector<vector<Edge<T>>> g;
    int es;

    Graph() = default;

    explicit Graph(int n)
      : g(n)
      , es(0) {
    }

    size_t size() const {
        return g.size();
    }

    void resize(int n) {
        g.resize(n);
    }

    void add_edge(int from, int to, T cost = 1, T b = 1) {
        g[from].emplace_back(from, to, cost, b, es);
        g[to].emplace_back(to, from, cost, b, es++);
    }

    inline vector<Edge<T>>& operator[](const int& k) {
        return g[k];
    }

    inline const vector<Edge<T>>& operator[](const int& k) const {
        return g[k];
    }
};

template <typename T = int>
using Edges = vector<Edge<T>>;

template <typename T>
struct ShortestPath {
    vector<T> dist;
    vector<int> from, id;
};

template <typename T>
ShortestPath<T> dijkstra(const Graph<T> &g, int s, T w) {
    const auto INF = inf;
    vector<T> dist(g.size(), INF);
    vector<int> from(g.size(), -1), id(g.size(), -1);
    using Pi = pair<T, int>;
    priority_queue<Pi, vector<Pi>, greater<>> que;
    dist[s] = 0;
    que.emplace(dist[s], s);
    while(!que.empty()) {
        T cost;
        int idx;
        tie(cost, idx) = que.top();
        que.pop();
        if(dist[idx] < cost) continue;
        for(auto &e : g[idx]) {
            auto next_cost = cost + e.cost;
            if(e.b < w) continue;
            if(dist[e.to] <= next_cost) continue;
            dist[e.to] = next_cost;
            from[e.to] = idx;
            id[e.to] = e.idx;
            que.emplace(dist[e.to], e.to);
        }
    }
    return {dist, from, id};
}

int main() {
    ll N, M, X;
    cin >> N >> M >> X;
    Graph<ll> G(N);
    rep(i, M){
        ll u, v, a, b;
        cin >> u >> v >> a >> b;
        --u, --v;
        G.add_edge(u, v, a, b);
    }
    ll ok = 0, ng = 1e9 + 10;
    auto check = [&](ll w) -> bool{
        auto [dist, from, id] = dijkstra(G, 0, w);
        return dist[N - 1] <= X;
    };
    while(abs(ok - ng) > 1){
        ll mid = abs(ok + ng) / 2;
        if(check(mid)) ok = mid;
        else ng = mid;
    }
    if(ok == 0) cout << -1 << endl;
    else cout << ok << endl;
}
0