結果
問題 | No.1805 Approaching Many Typhoon |
ユーザー |
|
提出日時 | 2022-01-12 21:10:45 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 1 ms / 2,000 ms |
コード長 | 2,223 bytes |
コンパイル時間 | 14,705 ms |
コンパイル使用メモリ | 383,404 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-15 15:05:41 |
合計ジャッジ時間 | 14,550 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 35 |
ソースコード
#[macro_export]macro_rules! setup {{ mut $input:ident: SplitWhitespace $(,)? } => {use std::io::Read;let mut buf = String::new();std::io::stdin().read_to_string(&mut buf).unwrap();let mut $input = buf.split_whitespace();};}#[macro_export]macro_rules! parse_next {($str_iter:expr) => {$str_iter.next().unwrap().parse().unwrap()};}fn main() {setup! { mut input: SplitWhitespace };let _n: usize = parse_next!(input);let m: usize = parse_next!(input);let s: usize = parse_next!(input);let g: usize = parse_next!(input);let mut f: Vec<usize> = vec![];let mut t: Vec<usize> = vec![];(0..m).for_each(|_| {f.push(parse_next!(input));t.push(parse_next!(input));});let u: usize = parse_next!(input);let i: Vec<usize> = (0..u).map(|_| parse_next!(input)).collect();let ans = match (|| {use std::collections::{HashSet, VecDeque};let mut queue = VecDeque::new();let mut visited = HashSet::new();let mut depth = 0;{let root = s;queue.push_back(root);visited.insert(root);}while !queue.is_empty() {for _ in 0..queue.len() {let from = match queue.pop_front() {Some(value) => value,None => unreachable!(),};if from == g {return Some(depth);}let children = (0..m).filter(|&k| f[k] == from).map(|k| t[k]).chain((0..m).filter(|&k| t[k] == from).map(|k| f[k])).filter(|&island| !i.contains(&island)).collect::<Vec<_>>();for &to in children.iter() {if visited.contains(&to) {continue;}queue.push_back(to);visited.insert(to);}}depth += 1;}None})() {Some(_) => "Yes",None => "No",};println!("{}", ans);}