結果
問題 | No.1473 おでぶなおばけさん |
ユーザー | uw_yu1rabbit |
提出日時 | 2021-04-09 22:57:46 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 451 ms / 2,000 ms |
コード長 | 3,511 bytes |
コンパイル時間 | 12,359 ms |
コンパイル使用メモリ | 388,972 KB |
実行使用メモリ | 14,464 KB |
最終ジャッジ日時 | 2024-06-25 06:41:18 |
合計ジャッジ時間 | 19,515 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,812 KB |
testcase_01 | AC | 1 ms
6,816 KB |
testcase_02 | AC | 258 ms
13,844 KB |
testcase_03 | AC | 111 ms
12,032 KB |
testcase_04 | AC | 169 ms
8,576 KB |
testcase_05 | AC | 53 ms
6,940 KB |
testcase_06 | AC | 215 ms
12,288 KB |
testcase_07 | AC | 202 ms
14,464 KB |
testcase_08 | AC | 413 ms
14,464 KB |
testcase_09 | AC | 166 ms
14,440 KB |
testcase_10 | AC | 39 ms
8,448 KB |
testcase_11 | AC | 42 ms
9,984 KB |
testcase_12 | AC | 38 ms
9,376 KB |
testcase_13 | AC | 25 ms
6,944 KB |
testcase_14 | AC | 18 ms
6,940 KB |
testcase_15 | AC | 36 ms
8,448 KB |
testcase_16 | AC | 35 ms
7,808 KB |
testcase_17 | AC | 3 ms
6,944 KB |
testcase_18 | AC | 6 ms
6,944 KB |
testcase_19 | AC | 51 ms
7,936 KB |
testcase_20 | AC | 87 ms
10,880 KB |
testcase_21 | AC | 100 ms
9,984 KB |
testcase_22 | AC | 71 ms
11,904 KB |
testcase_23 | AC | 61 ms
11,136 KB |
testcase_24 | AC | 56 ms
10,368 KB |
testcase_25 | AC | 435 ms
11,520 KB |
testcase_26 | AC | 451 ms
11,648 KB |
testcase_27 | AC | 64 ms
6,944 KB |
testcase_28 | AC | 295 ms
14,208 KB |
testcase_29 | AC | 123 ms
9,856 KB |
testcase_30 | AC | 191 ms
11,136 KB |
testcase_31 | AC | 173 ms
13,952 KB |
testcase_32 | AC | 120 ms
12,656 KB |
testcase_33 | AC | 97 ms
10,496 KB |
testcase_34 | AC | 63 ms
6,944 KB |
testcase_35 | AC | 40 ms
6,940 KB |
testcase_36 | AC | 95 ms
8,576 KB |
testcase_37 | AC | 217 ms
10,496 KB |
testcase_38 | AC | 21 ms
6,940 KB |
testcase_39 | AC | 36 ms
7,936 KB |
testcase_40 | AC | 36 ms
7,936 KB |
testcase_41 | AC | 35 ms
7,296 KB |
testcase_42 | AC | 35 ms
7,424 KB |
testcase_43 | AC | 83 ms
10,880 KB |
testcase_44 | AC | 83 ms
10,948 KB |
testcase_45 | AC | 83 ms
10,880 KB |
testcase_46 | AC | 59 ms
9,600 KB |
testcase_47 | AC | 76 ms
11,264 KB |
testcase_48 | AC | 77 ms
10,880 KB |
ソースコード
//use proconio::input; fn main() { let t = std::io::stdin(); let mut read = snio::Reader::new(t.lock()); let n = read.usize(); let m = read.usize(); let road_and_dist:Vec<(usize,usize,usize)> = (0..m).map(|_| (read.usize(),read.usize(), read.usize())).collect(); let mut shojin = vec![Vec::new();n]; for (s,t,u) in road_and_dist { shojin[s - 1].push((t - 1,u)); shojin[t - 1].push((s - 1,u)); } let t = binary_search(&shojin); println!("{} {}",t,dijkstra(&shojin,t,0)); } fn binary_search(shojin:&Vec<Vec<(usize,usize)>>) -> usize { let (mut lb , mut ub) = (0,1e9 as usize + 1); while ub - lb > 1 { let mid = (ub + lb) / 2; if dijkstra(shojin,mid,0) != 1e18 as usize{ lb = mid; } else { ub = mid; } } lb } use std::collections::BinaryHeap; use std::cmp::Reverse; fn dijkstra(shojin:& Vec<Vec<(usize,usize)>>,debu:usize,start:usize) -> usize{ let mut pq = BinaryHeap::new(); let mut dist = vec![1e18 as usize;shojin.len()]; pq.push(Reverse((0,start))); dist[start] = 0; while let Some(v) = pq.pop() { let (cost,now) = v.0; for (to,c) in &shojin[now] { if dist[now] < cost || *c < debu{ continue; } if dist[*to] > 1 + dist[now] { dist[*to] = dist[now] + 1; pq.push(Reverse((dist[*to],*to))); } } } //println!("{}",dist[shojin.len() - 1]); dist[shojin.len() - 1] } #[allow(dead_code)] pub mod snio { pub struct Reader<R: std::io::BufRead> { reader: R, buf: std::collections::VecDeque<String>, } impl<R: std::io::BufRead> Reader<R> { pub fn new(reader: R) -> Self { Self { reader, buf: std::collections::VecDeque::new(), } } fn load(&mut self) { while self.buf.is_empty() { let mut s = String::new(); let length = self.reader.read_line(&mut s).unwrap(); if length == 0 { break; } self.buf.extend(s.split_whitespace().map(|s| s.to_owned())); } } pub fn string(&mut self) -> String { self.load(); self.buf.pop_front().unwrap_or_else(|| panic!("input ended")) } pub fn char(&mut self) -> char { let string = self.string(); let mut chars = string.chars(); let res = chars.next().unwrap(); assert!(chars.next().is_none(), "invalid input!"); res } pub fn chars(&mut self) -> Vec<char> { self.read::<String>().chars().collect() } pub fn read<T: std::str::FromStr>(&mut self) -> T where <T as ::std::str::FromStr>::Err: ::std::fmt::Debug, { self.string().parse::<T>().expect("Failed to parse the input.") } } macro_rules! definition_of_reader_of_numbers { ($($ty:tt,)*) => { impl <R:std::io::BufRead> Reader<R> { $( #[inline] pub fn $ty (&mut self) -> $ty { self.read::<$ty>() } )* } } } definition_of_reader_of_numbers! { u8,u16,u32,u64,usize, i8,i16,i32,i64,isize, } }