結果
問題 | No.92 逃走経路 |
ユーザー |
|
提出日時 | 2020-05-26 00:49:39 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 61 ms / 5,000 ms |
コード長 | 2,322 bytes |
コンパイル時間 | 14,487 ms |
コンパイル使用メモリ | 390,936 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-10-13 02:23:12 |
合計ジャッジ時間 | 15,895 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 18 |
ソースコード
use std::collections::{VecDeque, HashMap};fn main() {let mut nmk = String::new();std::io::stdin().read_line(&mut nmk).ok();let nmk: Vec<usize> = nmk.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();let n = nmk[0];let m = nmk[1];let mut t2c2t: Vec<HashMap<usize, Vec<usize>>> = vec![HashMap::new(); n];let mut c2ts: HashMap<usize, Vec<usize>> = HashMap::new();for _ in 0..m {let mut abc = String::new();std::io::stdin().read_line(&mut abc).ok();let abc: Vec<usize> = abc.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();let a = abc[0] - 1;let b = abc[1] - 1;let c = abc[2];if let Some(x) = t2c2t[a].get_mut(&c) {(*x).push(b);} else {t2c2t[a].insert(c, vec!{b});}if let Some(x) = t2c2t[b].get_mut(&c) {(*x).push(a);} else {t2c2t[b].insert(c, vec!{a});}if c2ts.get(&c).is_none() {c2ts.insert(c, vec!{a, b});} else {if !c2ts.get(&c).unwrap().contains(&a) {c2ts.get_mut(&c).unwrap().push(a);}if !c2ts.get(&c).unwrap().contains(&b) {c2ts.get_mut(&c).unwrap().push(b);}}}let mut d = String::new();std::io::stdin().read_line(&mut d).ok();let mut d: VecDeque<usize> = d.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();let mut cands: VecDeque<usize> = VecDeque::new();let l = d.pop_front().unwrap();c2ts.get(&l).unwrap().iter().for_each(|t| cands.push_back(*t));while !d.is_empty() {let cost = d.pop_front().unwrap();let lim = cands.len();for _ in 0..lim {let town = cands.pop_front().unwrap();if let Some(x) = t2c2t[town].get(&cost) {(*x).iter().for_each(|t| {cands.push_back(*t);});}}let mut temp: Vec<usize> = cands.iter().map(|i| *i).collect();temp.sort();temp.dedup();cands = temp.iter().map(|i| *i).collect();}println!("{}", cands.len());println!("{}", cands.iter().map(|i| (i+1).to_string()).collect::<Vec<String>>().join(" "));}