結果

問題 No.2387 Yokan Factory
ユーザー umimelumimel
提出日時 2023-07-21 21:51:24
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 367 ms / 5,000 ms
コード長 2,476 bytes
コンパイル時間 1,859 ms
コンパイル使用メモリ 180,624 KB
実行使用メモリ 13,380 KB
最終ジャッジ日時 2023-10-21 21:50:28
合計ジャッジ時間 5,618 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 1 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 1 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 1 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 1 ms
4,348 KB
testcase_15 AC 187 ms
13,092 KB
testcase_16 AC 115 ms
13,380 KB
testcase_17 AC 297 ms
12,084 KB
testcase_18 AC 282 ms
11,016 KB
testcase_19 AC 218 ms
9,000 KB
testcase_20 AC 181 ms
8,360 KB
testcase_21 AC 367 ms
10,664 KB
testcase_22 AC 167 ms
7,932 KB
testcase_23 AC 244 ms
8,936 KB
testcase_24 AC 96 ms
8,320 KB
testcase_25 AC 27 ms
6,664 KB
testcase_26 AC 51 ms
9,520 KB
testcase_27 AC 57 ms
10,232 KB
testcase_28 AC 3 ms
4,348 KB
testcase_29 AC 4 ms
4,348 KB
testcase_30 AC 3 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 3 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 pll = pair<ll, ll>;
#define drep(i, cc, n) for (ll i = (cc); i <= (n); ++i)
#define rep(i, n) drep(i, 0, n - 1)
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define fi first
#define se second

mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());
const ll MOD1000000007 = 1000000007;
const ll MOD998244353 = 998244353;
const ll MOD[3] = {999727999, 1070777777, 1000000007};
const ll LINF = 1LL << 60;
const int IINF = (1 << 30) - 1;

template<typename T> 
struct Edge{
    int to; 
    T w;
    T b;
    Edge(int to_, T w_, T b_){
        to = to_;
        w=w_;
        b=b_;
    }
};
template<typename T> using Tree = vector<vector<Edge<T>>>;
template<typename T> using Graph = vector<vector<Edge<T>>>;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    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[u].pb(Edge<ll>(v, a, b));
        G[v].pb(Edge<ll>(u, a, b));
    }

    //輸送可能チェック
    {
        vector<ll> dist(n, LINF);
        dist[0] = 0;
        priority_queue<pll, vector<pll>, greater<pll>> PQ;
        PQ.push({0, 0});
        while(!PQ.empty()){
            ll v = PQ.top().se;
            ll tmp = PQ.top().fi;
            PQ.pop();
            if(dist[v] < tmp) continue;

            for(Edge<ll> e : G[v]){
                if(dist[v]+e.w < dist[e.to]){
                    dist[e.to] = dist[v] + e.w;
                    PQ.push({dist[e.to], e.to});
                }
            }
        }

        if(dist[n-1]>x){
            cout << -1 << endl;
            return 0;
        }
    }

    ll low = 0;
    ll high = 1e9+1;
    ll mid;
    while(high-low>1){
        mid = (low + high)/2;

        vector<ll> dist(n, LINF);
        dist[0] = 0;
        priority_queue<pll, vector<pll>, greater<pll>> PQ;
        PQ.push({0, 0});
        while(!PQ.empty()){
            ll v = PQ.top().se;
            ll tmp = PQ.top().fi;
            PQ.pop();
            if(dist[v] < tmp) continue;

            for(Edge<ll> e : G[v]){
                if(dist[v]+e.w<dist[e.to] && mid<=e.b){
                    dist[e.to] = dist[v] + e.w;
                    PQ.push({dist[e.to], e.to});
                }
            }
        }

        if(dist[n-1]<=x) low = mid;
        else high = mid;
    }

    cout << low << endl;
}
0