結果
問題 |
No.1473 おでぶなおばけさん
|
ユーザー |
![]() |
提出日時 | 2021-04-14 21:12:44 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 993 ms / 2,000 ms |
コード長 | 1,919 bytes |
コンパイル時間 | 4,347 ms |
コンパイル使用メモリ | 204,624 KB |
最終ジャッジ日時 | 2025-01-20 17:42:25 |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 47 |
ソースコード
#include "bits/stdc++.h" #define MOD 1000000007 #define rep(i, n) for(ll i=0; i < (n); i++) #define rrep(i, n) for(ll i=(n)-1; i >=0; i--) #define ALL(v) v.begin(),v.end() #define rALL(v) v.rbegin(),v.rend() #define FOR(i, j, k) for(ll i=j;i<k;i++) #define debug_print(var) cerr << #var << "=" << var <<endl; #define DUMP(i, v)for(ll i=0;i<v.size();i++)cerr<<v[i]<<" " #define fi first #define se second using namespace std; typedef long long int ll; typedef vector<ll> llvec; typedef vector<double> dvec; typedef pair<ll, ll> P; typedef long double ld; struct edge{ll x, c;}; ll W; struct dijkstra{ ll N; llvec d; vector<vector<edge>> e; dijkstra(ll n){ N = n; //d = llvec(N, 1e18); e = vector<vector<edge>>(N); } void add_edge(ll from, ll to, ll cost){ e[from].push_back({to, cost}); } void run(ll start){ priority_queue<P, vector<P>, greater<P>> que; que.push({0, start}); d = llvec(N, 1e18); d[start]=0; while(!que.empty()){ P q = que.top();que.pop(); ll dc = q.first; ll x = q.second; if(dc>d[x]){ continue; }else{ for(auto ip: e[x]){ if(W>ip.c)continue; if(d[ip.x]<=d[x]+1){ continue; }else{ d[ip.x]= d[x]+1; que.push({d[ip.x], ip.x}); } } } } } }; /************************************** ** A main function starts from here ** ***************************************/ int main(){ ll N, M; cin >> N >> M; dijkstra dijk(N); rep(i, M){ ll a, b, c; cin >> a >> b >> c; a--;b--; dijk.add_edge(a, b, c); dijk.add_edge(b, a, c); } ll ok = 0; ll ng = 1e18; while(abs(ok-ng)>1){ W =(ok+ng)/2; dijk.run(0); if(dijk.d[N-1]<1e18){ ok = W; }else{ ng = W; } } W = ok; dijk.run(0); cout << W << " " << dijk.d.back()<<endl; return 0; }