結果

問題 No.2387 Yokan Factory
ユーザー Rubikun
提出日時 2023-07-21 21:25:45
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 471 ms / 5,000 ms
コード長 1,532 bytes
コンパイル時間 2,416 ms
コンパイル使用メモリ 202,952 KB
最終ジャッジ日時 2025-02-15 16:15:50
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 35
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=998244353,MAX=300005;
const ll INF=1LL<<60;

vector<pair<int,pair<int,int>>> G[MAX];
ll dis[MAX];

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll N,M,X;cin>>N>>M>>X;
    for(int i=0;i<M;i++){
        int a,b,c,d;cin>>a>>b>>c>>d;a--;b--;
        G[a].push_back(mp(b,mp(c,d)));
        G[b].push_back(mp(a,mp(c,d)));
    }
    ll left=0,right=2e9;
    while(right-left>1){
        ll mid=(left+right)/2;
        for(int i=0;i<N;i++) dis[i]=INF;
        dis[0]=0;
        
        priority_queue<pair<ll,int>,vector<pair<ll,int>>,greater<pair<ll,int>>> PQ;
        PQ.push(mp(0,0));
        
        while(!PQ.empty()){
            auto [d,u]=PQ.top();PQ.pop();
            if(dis[u]<d) continue;
            for(auto to:G[u]){
                auto t=to.fi;
                auto [a,b]=to.se;
                if(b<mid) continue;
                if(chmin(dis[t],dis[u]+a)) PQ.push(mp(dis[t],t));
            }
        }
        
        if(dis[N-1]<=X) left=mid;
        else right=mid;
    }
    
    if(left==0) left=-1;
    cout<<left<<endl;
}
0