結果
問題 | No.1473 おでぶなおばけさん |
ユーザー | taotao54321 |
提出日時 | 2021-04-16 01:16:11 |
言語 | Rust (1.77.0) |
結果 |
AC
|
実行時間 | 168 ms / 2,000 ms |
コード長 | 2,828 bytes |
コンパイル時間 | 1,959 ms |
コンパイル使用メモリ | 146,644 KB |
実行使用メモリ | 16,640 KB |
最終ジャッジ日時 | 2023-09-15 03:38:21 |
合計ジャッジ時間 | 8,479 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,380 KB |
testcase_01 | AC | 1 ms
4,380 KB |
testcase_02 | AC | 136 ms
16,244 KB |
testcase_03 | AC | 67 ms
12,576 KB |
testcase_04 | AC | 66 ms
9,640 KB |
testcase_05 | AC | 27 ms
4,384 KB |
testcase_06 | AC | 110 ms
12,764 KB |
testcase_07 | AC | 99 ms
16,612 KB |
testcase_08 | AC | 168 ms
16,640 KB |
testcase_09 | AC | 85 ms
16,612 KB |
testcase_10 | AC | 19 ms
8,232 KB |
testcase_11 | AC | 21 ms
9,776 KB |
testcase_12 | AC | 19 ms
9,100 KB |
testcase_13 | AC | 12 ms
5,924 KB |
testcase_14 | AC | 9 ms
4,976 KB |
testcase_15 | AC | 18 ms
8,684 KB |
testcase_16 | AC | 18 ms
7,480 KB |
testcase_17 | AC | 2 ms
4,380 KB |
testcase_18 | AC | 4 ms
4,376 KB |
testcase_19 | AC | 30 ms
8,428 KB |
testcase_20 | AC | 49 ms
11,452 KB |
testcase_21 | AC | 57 ms
10,212 KB |
testcase_22 | AC | 31 ms
12,304 KB |
testcase_23 | AC | 27 ms
10,736 KB |
testcase_24 | AC | 26 ms
11,028 KB |
testcase_25 | AC | 151 ms
12,020 KB |
testcase_26 | AC | 156 ms
14,128 KB |
testcase_27 | AC | 30 ms
5,688 KB |
testcase_28 | AC | 142 ms
16,504 KB |
testcase_29 | AC | 57 ms
10,468 KB |
testcase_30 | AC | 85 ms
13,408 KB |
testcase_31 | AC | 80 ms
14,184 KB |
testcase_32 | AC | 70 ms
13,096 KB |
testcase_33 | AC | 50 ms
11,112 KB |
testcase_34 | AC | 28 ms
6,668 KB |
testcase_35 | AC | 20 ms
6,672 KB |
testcase_36 | AC | 48 ms
9,112 KB |
testcase_37 | AC | 80 ms
11,356 KB |
testcase_38 | AC | 10 ms
4,376 KB |
testcase_39 | AC | 18 ms
7,724 KB |
testcase_40 | AC | 18 ms
7,732 KB |
testcase_41 | AC | 18 ms
7,292 KB |
testcase_42 | AC | 18 ms
7,268 KB |
testcase_43 | AC | 23 ms
11,292 KB |
testcase_44 | AC | 23 ms
11,280 KB |
testcase_45 | AC | 23 ms
11,288 KB |
testcase_46 | AC | 42 ms
10,128 KB |
testcase_47 | AC | 56 ms
11,540 KB |
testcase_48 | AC | 59 ms
11,352 KB |
ソースコード
//! # Bundled libraries //! //! - `procon-rs-prelude 0.1.0 (git+https://github.com/taotao54321/procon-rs-prelude.git#82725166a669a60e41cb6565bc10ef4fc2fe3e11)` licensed under **missing** as `crate::procon_rs_prelude` #![allow(clippy::many_single_char_names)] /*#[macro_use] extern crate procon_rs_prelude as _;*/ use std::collections::VecDeque; use std::io::Read as _; fn solve(n: usize, graph: &[Vec<(usize, u32)>]) -> (u32, u32) { const W_MAX: u32 = 10_u32.pow(9) + 1; let mut ans_k = try_bfs(n, graph, 1).unwrap(); let mut lo = 1; let mut hi = W_MAX; while lo + 1 < hi { let mid = (lo + hi) / 2; if let Some(k) = try_bfs(n, graph, mid) { ans_k = k; lo = mid; } else { hi = mid; } } (lo, ans_k) } fn try_bfs(n: usize, graph: &[Vec<(usize, u32)>], w: u32) -> Option<u32> { const INF: u32 = u32::MAX; let mut ks = vec![INF; n]; let mut que = VecDeque::new(); ks[0] = 0; que.push_back(0); while !que.is_empty() { let s = que.pop_front().unwrap(); let k_new = ks[s] + 1; for &(t, d) in &graph[s] { if d < w { continue; } if chmin!(ks[t], k_new) { que.push_back(t); } } } let res = ks[n - 1]; (res != INF).then(|| res) } fn main() { let mut input = String::new(); std::io::stdin().read_to_string(&mut input).unwrap(); let mut tokens = input.split_ascii_whitespace(); macro_rules! read { ($ty:ty) => {{ tokens.next().unwrap().parse::<$ty>().unwrap() }}; } let n = read!(usize); let m = read!(usize); let mut graph: Vec<Vec<(usize, u32)>> = vec![vec![]; n]; for _ in 0..m { let s = read!(usize) - 1; let t = read!(usize) - 1; let d = read!(u32); graph[s].push((t, d)); graph[t].push((s, d)); } let (ans_w, ans_k) = solve(n, &graph); println!("{} {}", ans_w, ans_k); } // The following code was expanded by `cargo-equip`. #[allow(clippy::deprecated_cfg_attr)]#[cfg_attr(rustfmt,rustfmt::skip)]#[allow(unused)]pub mod procon_rs_prelude{pub use crate::{chmax,chmin,dbg,debug};#[macro_export]macro_rules!chmin{($xmin:expr,$x:expr)=>{{if$x<$xmin{$xmin=$x;true}else{false}}};}#[macro_export]macro_rules!chmax{($xmax:expr,$x:expr)=>{{if$xmax<$x{$xmax=$x;true}else{false}}};}#[macro_export]macro_rules!debug{($($x:expr),+$(,)?)=>{{#[cfg(debug_assertions)]::std::eprintln!(::std::concat!("[{}:{}]",$(" ",::std::stringify!($x),"={:?}"),+),::std::path::Path::new(::std::file!()).file_name().unwrap().to_str().unwrap(),::std::line!(),$($x),+);}};}#[macro_export]macro_rules!dbg{($($_:expr),*$(,)*)=>{{::std::compile_error!("DO NOT USE std::dbg! for procon!");}};}}