結果
問題 | No.2387 Yokan Factory |
ユーザー | HIcoder |
提出日時 | 2023-07-21 21:44:59 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 575 ms / 5,000 ms |
コード長 | 1,403 bytes |
コンパイル時間 | 1,003 ms |
コンパイル使用メモリ | 95,936 KB |
実行使用メモリ | 13,024 KB |
最終ジャッジ日時 | 2024-09-21 23:11:48 |
合計ジャッジ時間 | 6,980 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 35 |
ソースコード
#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; }