結果
問題 | No.2387 Yokan Factory |
ユーザー |
![]() |
提出日時 | 2023-07-21 21:45:26 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 419 ms / 5,000 ms |
コード長 | 1,478 bytes |
コンパイル時間 | 1,828 ms |
コンパイル使用メモリ | 178,388 KB |
実行使用メモリ | 13,252 KB |
最終ジャッジ日時 | 2024-09-21 23:12:21 |
合計ジャッジ時間 | 6,645 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 35 |
ソースコード
#include <bits/stdc++.h>using namespace std;using ll =long long;#define all(v) v.begin(),v.end()#define rep(i,a,b) for(int i=a;i<b;i++)#define rrep(i,a,b) for(int i=a;i>=b;i--)ll INF=2e18;int main() {ios::sync_with_stdio(false);cin.tie(0);ll N,M,X;cin>>N>>M>>X;vector<vector<pair<ll,ll>>> vec(N,vector<pair<ll,ll>>(0));vector<ll> a(M),b(M);for(ll i=0;i<M;i++) {ll u,v;cin>>u>>v;cin>>a[i]>>b[i];u--;v--;vec[u].push_back(make_pair(v,i));vec[v].push_back(make_pair(u,i));}ll s=1;ll g=1000000000;while(s<g) {ll k=(s+g+1)/2;vector<ll> d(N,INF);d[0]=0;priority_queue<pair<ll,ll>,vector<pair<ll,ll>>,greater<pair<ll,ll>>> S;S.push(make_pair(0,0));while(!S.empty()) {auto p=S.top();S.pop();if(d[p.second]<p.first) continue;for(auto x:vec[p.second]) {if(b[x.second]<k) continue;if(d[x.first]>p.first+a[x.second]) {d[x.first]=p.first+a[x.second];S.push(make_pair(d[x.first],x.first));}}}if(d[N-1]<=X) s=k;else g=k-1;}vector<ll> d(N,INF);d[0]=0;priority_queue<pair<ll,ll>,vector<pair<ll,ll>>,greater<pair<ll,ll>>> S;S.push(make_pair(0,0));while(!S.empty()) {auto p=S.top();S.pop();if(d[p.second]<p.first) continue;for(auto x:vec[p.second]) {if(d[x.first]>p.first+a[x.second]) {d[x.first]=p.first+a[x.second];S.push(make_pair(d[x.first],x.first));}}}if(d[N-1]>X) {cout<<-1<<endl;return 0;}cout<<s<<endl;}