結果
問題 | No.1480 Many Complete Graphs |
ユーザー | akakimidori |
提出日時 | 2021-04-16 21:05:30 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 82 ms / 2,000 ms |
コード長 | 2,556 bytes |
コンパイル時間 | 19,023 ms |
コンパイル使用メモリ | 402,480 KB |
実行使用メモリ | 19,456 KB |
最終ジャッジ日時 | 2024-07-03 04:12:04 |
合計ジャッジ時間 | 17,038 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 57 |
コンパイルメッセージ
warning: unused variable: `out` --> src/main.rs:42:45 | 42 | fn run<W: Write>(sc: &mut scanner::Scanner, out: &mut std::io::BufWriter<W>) { | ^^^ help: if this is intentional, prefix it with an underscore: `_out` | = note: `#[warn(unused_variables)]` on by default
ソースコード
// ---------- begin scannner ---------- #[allow(dead_code)] mod scanner { use std::str::FromStr; pub struct Scanner<'a> { it: std::str::SplitWhitespace<'a>, } impl<'a> Scanner<'a> { pub fn new(s: &'a String) -> Scanner<'a> { Scanner { it: s.split_whitespace(), } } pub fn next<T: FromStr>(&mut self) -> T { self.it.next().unwrap().parse::<T>().ok().unwrap() } pub fn next_bytes(&mut self) -> Vec<u8> { self.it.next().unwrap().bytes().collect() } pub fn next_chars(&mut self) -> Vec<char> { self.it.next().unwrap().chars().collect() } pub fn next_vec<T: FromStr>(&mut self, len: usize) -> Vec<T> { (0..len).map(|_| self.next()).collect() } } } // ---------- end scannner ---------- use std::io::Write; fn main() { use std::io::Read; let mut s = String::new(); std::io::stdin().read_to_string(&mut s).unwrap(); let mut sc = scanner::Scanner::new(&s); let out = std::io::stdout(); let mut out = std::io::BufWriter::new(out.lock()); run(&mut sc, &mut out); } fn run<W: Write>(sc: &mut scanner::Scanner, out: &mut std::io::BufWriter<W>) { let n: usize = sc.next(); let m: usize = sc.next(); let mut g = vec![vec![]; n + 1]; for _ in 0..m { let k: usize = sc.next(); let c: u64 = sc.next(); let s: Vec<usize> = sc.next_vec(k); let zero = g.len(); g.push(vec![]); let one = g.len(); g.push(vec![]); for &s in s.iter() { let d = (s / 2) as u64; if s & 1 == 0 { g[s].push((zero, c + d)); g[zero].push((s, d)); g[one].push((s, d)); } else { g[s].push((one, c + d + 1)); g[zero].push((s, d + 1)); g[one].push((s, d)); } } } use std::cmp::Reverse; let inf = std::u64::MAX; let mut dp = vec![inf; g.len()]; dp[1] = 1; let mut h = std::collections::BinaryHeap::new(); h.push(Reverse((0, 1))); while let Some(Reverse((d, v))) = h.pop() { if d > dp[v] { continue; } for &(u, w) in g[v].iter() { let d = d + w; if d < dp[u] { dp[u] = d; h.push(Reverse((d, u))); } } } if dp[n] != inf { println!("{}", dp[n]); } else { println!("-1"); } }