結果

問題 No.2387 Yokan Factory
ユーザー milanis48663220milanis48663220
提出日時 2023-07-21 21:43:14
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 689 ms / 5,000 ms
コード長 2,714 bytes
コンパイル時間 1,172 ms
コンパイル使用メモリ 131,704 KB
実行使用メモリ 18,544 KB
最終ジャッジ日時 2023-10-21 21:41:31
合計ジャッジ時間 6,878 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 1 ms
4,348 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 1 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 350 ms
18,356 KB
testcase_16 AC 249 ms
18,180 KB
testcase_17 AC 422 ms
18,544 KB
testcase_18 AC 596 ms
16,656 KB
testcase_19 AC 455 ms
11,868 KB
testcase_20 AC 341 ms
11,308 KB
testcase_21 AC 689 ms
15,580 KB
testcase_22 AC 325 ms
10,580 KB
testcase_23 AC 505 ms
12,132 KB
testcase_24 AC 332 ms
10,892 KB
testcase_25 AC 25 ms
8,764 KB
testcase_26 AC 48 ms
13,168 KB
testcase_27 AC 54 ms
14,916 KB
testcase_28 AC 4 ms
4,348 KB
testcase_29 AC 6 ms
4,348 KB
testcase_30 AC 5 ms
4,348 KB
testcase_31 AC 4 ms
4,348 KB
testcase_32 AC 3 ms
4,348 KB
testcase_33 AC 3 ms
4,348 KB
testcase_34 AC 5 ms
4,348 KB
testcase_35 AC 3 ms
4,348 KB
testcase_36 AC 3 ms
4,348 KB
testcase_37 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
typedef long long ll;

template<typename T>
vector<vector<T>> vec2d(int n, int m, T v){
    return vector<vector<T>>(n, vector<T>(m, v));
}

template<typename T>
vector<vector<vector<T>>> vec3d(int n, int m, int k, T v){
    return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v)));
}

template<typename T>
void print_vector(vector<T> v, char delimiter=' '){
    if(v.empty()) {
        cout << endl;
        return;
    }
    for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter;
    cout << v.back() << endl;
}

const ll INF = 2e+18;

typedef pair<ll, int> P;

struct edge{
    int to;
    ll cost;
    edge(int to, ll cost): to(to), cost(cost) {}
};

vector<ll> dijkstra(int s, vector<vector<edge>> G){
    priority_queue<P, vector<P>, greater<P>> que;
    int n = G.size();
    vector<ll> d(n, INF);
    d[s] = 0;
    que.push(P(0, s));
    while(!que.empty()){
        P p = que.top();que.pop();
        int v = p.second;
        if(d[v] < p.first) continue;
        for(int i = 0; i < G[v].size(); i++){
            edge e = G[v][i];
            if(d[v] + e.cost < d[e.to]){
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
    return d;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int n, m; ll x; cin >> n >> m >> x;
    vector<int> u(m), v(m);
    vector<ll> a(m), b(m);
    for(int i = 0; i < m; i++){
        cin >> u[i] >> v[i] >> a[i] >> b[i]; u[i]--; v[i]--;
    }
    auto judge = [&](int s){
        vector<vector<edge>> g(n);
        for(int i = 0; i < m; i++){
            if(b[i] >= s){
                g[u[i]].push_back(edge(v[i], a[i]));
                g[v[i]].push_back(edge(u[i], a[i]));
            }
        }
        auto d = dijkstra(0, g);
        return d[n-1] <= x;
    };
    if(!judge(0)){
        cout << -1 << endl;
        return 0;
    }
    ll l = 0, r = 1e9+5;
    while(r-l > 1){
        ll x = (l+r)/2;
        if(judge(x)) l = x;
        else r = x;
    }
    cout << l << endl;
}
0