結果
問題 |
No.1473 おでぶなおばけさん
|
ユーザー |
![]() |
提出日時 | 2021-04-09 21:50:27 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 214 ms / 2,000 ms |
コード長 | 1,371 bytes |
コンパイル時間 | 900 ms |
コンパイル使用メモリ | 81,432 KB |
実行使用メモリ | 9,600 KB |
最終ジャッジ日時 | 2024-06-25 05:04:00 |
合計ジャッジ時間 | 7,692 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 47 |
ソースコード
#include <iostream> #include <queue> using namespace std; template <typename T> struct Edge { int to; T cost; }; template <typename T> struct WeightedGraph { int n; std::vector<std::vector<Edge<T>>> g; WeightedGraph(){} WeightedGraph(int n) : n(n){ g.resize(n); } void add_edge(int from, int to, T cost){ g[from].push_back((Edge<T>){to, cost}); } }; int dist(WeightedGraph<int> &g, int k){ int n = g.n; int d[100005]; for(int i = 0; i < n; i++) d[i] = -1; queue<int> que; d[0] = 0; que.push(0); while(que.size()){ int u = que.front(); que.pop(); for(Edge<int> e : g.g[u]){ if(e.cost < k) continue; int v = e.to; if(d[v] == -1){ d[v] = d[u] + 1; que.push(v); } } } return d[n - 1]; } int main() { int n, m; cin >> n >> m; WeightedGraph<int> g(n); for(int i = 0; i < m; i++){ int s, t, d; cin >> s >> t >> d; s--; t--; g.add_edge(s, t, d); g.add_edge(t, s, d); } int left = 0, right = 1000000009; while(right - left > 1){ int mid = (right + left) / 2; if(dist(g, mid) >= 0) left = mid; else right = mid; } cout << left << " " << dist(g, left) << endl; }