結果
問題 |
No.1473 おでぶなおばけさん
|
ユーザー |
![]() |
提出日時 | 2022-03-23 13:34:42 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 270 ms / 2,000 ms |
コード長 | 1,327 bytes |
コンパイル時間 | 1,898 ms |
コンパイル使用メモリ | 176,652 KB |
実行使用メモリ | 11,824 KB |
最終ジャッジ日時 | 2024-10-11 11:19:48 |
合計ジャッジ時間 | 11,105 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 47 |
ソースコード
#include <bits/stdc++.h> using namespace std; struct Edge { int64_t to; // 辺の行先 int64_t weight; // 辺の重み Edge(int64_t t, int64_t w) : to(t), weight(w){} }; using Graph = vector<vector<Edge>>; int main() { int64_t N, M; cin >> N >> M; Graph G(N); int64_t S, T, D; for(int64_t i = 0; i < M; i++) { cin >> S >> T >> D; S--; T--; G[S].push_back(Edge(T, D)); G[T].push_back(Edge(S, D)); } int64_t ok = 1; int64_t ng = 1000000001; int64_t mid; const int64_t inf = 1000000001; queue<int64_t> q; int64_t ans; while(ng - ok != 1) { mid = (ng + ok) / 2; vector<int64_t> dist(N, inf); dist[0] = 0; q.push(0); while(!q.empty()) { int64_t p = q.front(); q.pop(); for(Edge e : G[p]) { if(e.weight < mid) continue; if(dist[p] + 1 < dist[e.to]) { dist[e.to] = dist[p] + 1; q.push(e.to); } } } if(dist[N - 1] != inf) { ok = mid; ans = dist[N - 1]; } else ng = mid; } if(ok == 1) { vector<int64_t> dist(N, inf); dist[0] = 0; q.push(0); while(!q.empty()) { int64_t p = q.front(); q.pop(); for(Edge e : G[p]) { if(dist[p] + 1 < dist[e.to]) { dist[e.to] = dist[p] + 1; q.push(e.to); } } } ans = dist[N - 1]; } cout << ok << ' ' << ans << endl; return 0; }