結果

問題 No.2387 Yokan Factory
ユーザー にしろ
提出日時 2024-04-26 03:41:03
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 402 ms / 5,000 ms
コード長 1,119 bytes
コンパイル時間 5,447 ms
コンパイル使用メモリ 315,912 KB
実行使用メモリ 13,024 KB
最終ジャッジ日時 2024-11-08 16:10:19
合計ジャッジ時間 10,719 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 35
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using ll = long long;
const ll inf=9e18;

int main(){

    ll n,m,x;
    cin >> n >> m >> x;
    vector<vector<array<ll,3>>> g(n);

    for(ll i=0;i<m;i++){
        ll u,v,a,b;
        cin >> u >> v >> a >> b;
        u--, v--;
        g[u].push_back({v,a,b});
        g[v].push_back({u,a,b});
    }

    ll ng=1e18+2,ok=-1;

    while(ng-ok>1){

        ll m=(ok+ng)/2;
        vector<ll> total_cost(n,inf);
        total_cost[0]=0;
        priority_queue<pair<ll,ll>,vector<pair<ll,ll>>,greater<pair<ll,ll>>> q;
        q.push({0,0});

        while(q.size()){
            auto[cost,now]=q.top();
            q.pop();
            if(total_cost[now]<cost) continue;
            for(auto[next,a,b]:g[now]){
                if(m>b) continue;
                if(total_cost[next]<=total_cost[now]+a) continue;
                total_cost[next]=total_cost[now]+a;
                q.push({total_cost[next],next});
            }
        }

        if(total_cost[n-1]<=x) ok=m;
        else ng=m;

    }

    if(ok==0) cout << -1;
    else cout << ok;
    
}
0