結果
問題 | No.1473 おでぶなおばけさん |
ユーザー |
![]() |
提出日時 | 2023-03-26 10:43:40 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 439 ms / 2,000 ms |
コード長 | 1,637 bytes |
コンパイル時間 | 1,523 ms |
コンパイル使用メモリ | 177,648 KB |
実行使用メモリ | 11,696 KB |
最終ジャッジ日時 | 2024-09-19 09:35:50 |
合計ジャッジ時間 | 10,707 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 47 |
ソースコード
#include<bits/stdc++.h> using namespace std; #define all(v) v.begin(),v.end() using ll = long long; using ull = unsigned long long; using vll=vector<ll>; using vvll = vector<vector<ll>>; const ll INF=1ll<<60; using P = pair<ll,ll>; int main(){ ll N,M; cin>>N>>M; vector<vector<P>> ab(N); for(int i=0;i<M;i++){ ll a,b,c; cin>>a>>b>>c; a--;b--; ab[a].push_back({c,b}); ab[b].push_back({c,a}); } ll l=0,r=1e16; while(r-l>1){ ll m=(r+l)/2; vector<ll> dist(N,INF); priority_queue<P,vector<P>,greater<P>> q; q.push({0,0}); dist[0]=0; while(!q.empty()){ auto x=q.top();q.pop(); ll cost=x.first,now=x.second; if(dist[now]<cost)continue; for(auto x2:ab[now]){ ll tcost=x2.first,to=x2.second; if(tcost<m)continue; if(dist[to]<=dist[now]+1)continue; dist[to]=dist[now]+1; q.push({dist[to],to}); } } if(dist[N-1]!=INF) l=m; else r=m; } ll m=l; vector<ll> dist(N,INF); priority_queue<P,vector<P>,greater<P>> q; q.push({0,0}); dist[0]=0; while(!q.empty()){ auto x=q.top();q.pop(); ll cost=x.first,now=x.second; if(dist[now]<cost)continue; for(auto x2:ab[now]){ ll tcost=x2.first,to=x2.second; if(tcost<m)continue; if(dist[to]<=dist[now]+1)continue; dist[to]=dist[now]+1; q.push({dist[to],to}); } } cout << l<<" "<<dist[N-1]<< endl; }