結果

問題 No.2387 Yokan Factory
ユーザー HIcoderHIcoder
提出日時 2023-07-21 21:44:59
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 618 ms / 5,000 ms
コード長 1,403 bytes
コンパイル時間 1,012 ms
コンパイル使用メモリ 95,908 KB
実行使用メモリ 13,144 KB
最終ジャッジ日時 2023-10-21 21:43:39
合計ジャッジ時間 7,020 ms
ジャッジサーバーID
(参考情報)
judge9 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 1 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 269 ms
13,144 KB
testcase_16 AC 169 ms
12,116 KB
testcase_17 AC 398 ms
12,140 KB
testcase_18 AC 296 ms
11,436 KB
testcase_19 AC 406 ms
9,412 KB
testcase_20 AC 272 ms
8,460 KB
testcase_21 AC 513 ms
10,984 KB
testcase_22 AC 246 ms
8,028 KB
testcase_23 AC 430 ms
9,260 KB
testcase_24 AC 190 ms
8,756 KB
testcase_25 AC 222 ms
6,872 KB
testcase_26 AC 525 ms
10,088 KB
testcase_27 AC 618 ms
10,800 KB
testcase_28 AC 4 ms
4,348 KB
testcase_29 AC 5 ms
4,348 KB
testcase_30 AC 4 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 4 ms
4,348 KB
testcase_36 AC 3 ms
4,348 KB
testcase_37 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<tuple>
using namespace std;

typedef long long ll;
const ll INF=1LL<<60;
typedef pair<ll,int> P;

struct edge{
    int from;
    int to;
    ll cost;
    ll width;
    edge(int from_,int to_,ll cost_,ll width_):from(from_),to(to_),cost(cost_),width(width_){};
};

int main(){
    int N,M;
    ll X;
    cin>>N>>M>>X;
    vector<vector<edge>> G(N);

    vector<edge> edges;

    
    for(int i=0;i<M;i++){
        int u,v,a,b;
        cin>>u>>v>>a>>b;
        u--;v--;

        G[u].emplace_back(u,v,a,b);
        G[v].emplace_back(v,u,a,b);
    }

    ll ub=INF,lb=0;//ubの大きさは必ず無理

    while(ub-lb>1){
        ll mid=(ub+lb)/2;

        vector<ll> dp(N,INF);
        priority_queue<P,vector<P>,greater<P>> pq;

        pq.emplace(0,0);//頂点0 コスト0

        while(!pq.empty()){
            auto [d,now]=pq.top();
            pq.pop();
            if(dp[now]<=d) continue;
            dp[now]=d;

            for(edge e:G[now]){
                if(e.width<mid) continue;

                if(dp[e.to]>dp[now]+e.cost){
                    pq.emplace(dp[now]+e.cost,e.to);
                }
            }
        }

        if(dp[N-1]<=X){
            lb=mid;
        }else{
            ub=mid;
        }
    }
    //cout<<"ub="<<ub<<endl;
    cout<<(lb==0?-1:lb)<<endl;

}
0