結果
問題 |
No.2387 Yokan Factory
|
ユーザー |
![]() |
提出日時 | 2023-07-22 01:44:20 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 553 ms / 5,000 ms |
コード長 | 1,414 bytes |
コンパイル時間 | 2,034 ms |
コンパイル使用メモリ | 205,968 KB |
最終ジャッジ日時 | 2025-02-15 17:54:32 |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 35 |
ソースコード
#define rep(i, n) for (int i = 0; i < (int)(n); i++) #define ALL(v) v.begin(), v.end() typedef long long ll; #include <bits/stdc++.h> using namespace std; const ll INF=1LL<<60; struct Edge{ int to; ll w; Edge(int to,ll w) : to(to),w(w) {} }; using Graph=vector<vector<Edge>>; using pli=pair<ll,int>; template<class T> bool chmin(T& a,T b){ if(a>b){ a=b; return true; } return false; } vector<ll> dijkstra(Graph& G,int s){ int n=G.size(); vector<ll> dist(n,INF); dist[s]=0; priority_queue<pli,vector<pli>,greater<pli>> que; que.push({dist[s],s}); while(!que.empty()){ int v=que.top().second; ll d=que.top().first; que.pop(); if(d>dist[v]) continue; for(auto e:G[v]){ if(chmin(dist[e.to],dist[v]+e.w)){ que.push({dist[e.to],e.to}); } } } return dist; } int main(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); ll n,m,x; cin>>n>>m>>x; vector<ll> U(m),V(m),A(m),B(m); rep(i,m){ cin>>U[i]>>V[i]>>A[i]>>B[i]; U[i]--,V[i]--; } ll ok=0,ng=1e9+7; while(ng-ok>1){ ll mid=(ok+ng)/2; Graph G(n); rep(i,m){ if(B[i]<mid) continue; G[U[i]].push_back(Edge(V[i],A[i])); G[V[i]].push_back(Edge(U[i],A[i])); } vector<ll> dis=dijkstra(G,0); if(dis[n-1]>x) ng=mid; else ok=mid; } if(ok==0) cout<<-1<<endl; else cout<<ok<<endl; return 0; }