結果
問題 | No.1473 おでぶなおばけさん |
ユーザー |
![]() |
提出日時 | 2021-12-01 23:08:23 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 170 ms / 2,000 ms |
コード長 | 1,731 bytes |
コンパイル時間 | 1,918 ms |
コンパイル使用メモリ | 181,956 KB |
実行使用メモリ | 12,416 KB |
最終ジャッジ日時 | 2024-07-05 00:57:49 |
合計ジャッジ時間 | 8,658 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 47 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) #define all(x) (x).begin(),(x).end() const int mod = 998244353; const int Mod = 1000000007; const long long INF = 1LL << 60; using ll = long long; using ld = long double; #define v2d(type,H,W,name,value) vector<vector<type>> name(H,vector<type>(W,value)); using plli = pair<ll ,int>; struct Edge { int to; ll w; Edge(int to, ll w):to(to),w(w) {} }; using Graph = vector<vector<Edge>>; template<class T> bool chmin(T& a, T b){ if (a>b){ a=b; return true; } else return false; } template<class T> bool chmax(T& a, T b){ if (a<b){ a=b; return true; } else return false; } int main() { int N,M,s; cin >> N >> M; s=0; Graph G(N+10); rep(i,M){ int a,b,w; cin >> a >> b >> w; a--;b--; G[a].push_back(Edge(b,w)); G[b].push_back(Edge(a,w)); } vector<ll> dist(N+10,0); dist[s]=INF; //plli : pair<ll ,int> priority_queue<plli> que; que.push(make_pair(dist[s],s)); while(!que.empty()){ int v=que.top().second; ll d=que.top().first; que.pop(); if(d<dist[v]) continue; //よって d>=dist[v] for(auto e:G[v]){ if(min(e.w,d)>dist[e.to]){ dist[e.to]=min(e.w,d); que.push(make_pair(dist[e.to],e.to)); } } } cout << dist[N-1] << " "; ll max_w=dist[N-1]; vector<ll> dist2(N,-1); dist2[0]=0; queue<int> que2; que2.push(0); while(!que2.empty()){ int qf=que2.front(); for(Edge e:G[qf]){ if(e.w<max_w) continue; ll x=e.to; if(dist2[x]==-1){ que2.push(x); dist2[x]=dist2[qf]+1; } } que2.pop(); } cout << dist2[N-1] << endl; }