結果
| 問題 |
No.2387 Yokan Factory
|
| コンテスト | |
| ユーザー |
soto800
|
| 提出日時 | 2023-07-21 21:40:03 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 536 ms / 5,000 ms |
| コード長 | 2,884 bytes |
| コンパイル時間 | 1,931 ms |
| コンパイル使用メモリ | 182,028 KB |
| 実行使用メモリ | 12,520 KB |
| 最終ジャッジ日時 | 2024-09-21 23:04:11 |
| 合計ジャッジ時間 | 7,448 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 35 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
template<class T>bool chmax(T & a, const T & b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
struct Edge {
long long to;
long long cost;
long long width;
};
using Graph = vector<vector<Edge>>;
using P = pair<long, int>;
const long long INF = 1LL << 60;
/* dijkstra(G,s,dis)
入力:グラフ G, 開始点 s, 距離を格納する dis
計算量:O(|E|log|V|)
副作用:dis が書き換えられる
*/
void dijkstra(const Graph &G, int s, vector<long long> &dis,lli targetWidth) {
int N = G.size();
dis.resize(N, INF);
priority_queue<P, vector<P>, greater<P>> pq; // 「仮の最短距離, 頂点」が小さい順に並ぶ
dis[s] = 0;
pq.emplace(dis[s], s);
while (!pq.empty()) {
P p = pq.top();
pq.pop();
int v = p.second;
if (dis[v] < p.first) { // 最短距離で無ければ無視
continue;
}
for (auto &e : G[v]) {
if (dis[e.to] > dis[v] + e.cost && targetWidth <= e.width) { // 最短距離候補なら priority_queue に追加
dis[e.to] = dis[v] + e.cost;
pq.emplace(dis[e.to], e.to);
}
}
}
}
void solve(){
lli N,M,X;
cin>>N>>M>>X;
Graph graph;
graph.resize(N);
REP(i,0,M){
lli u,v,a,b;
cin>>u>>v>>a>>b;
u--;
v--;
graph[u].push_back({v,a,b});
graph[v].push_back({u,a,b});
}
lli small = -1,large = 10000000000+10;
while(small+1 < large){
vector<lli> dist(N,INF);
lli middle = (small+large)/2;
dijkstra(graph,0,dist,middle);
if(dist[N-1] > X){
large = middle;
}
else{
small = middle;
}
}
cout<<small<<endl;
}
// Generated by 2.11.0 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
lli n;
//cin>>n;
n=1;
std::random_device seed_gen;
std::mt19937 engine(seed_gen());
while(n--)solve();
return 0;
}
soto800