結果
問題 | No.1647 Travel in Mitaru city 2 |
ユーザー | ikd |
提出日時 | 2021-08-14 15:53:13 |
言語 | Rust (1.77.0 + proconio) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,579 bytes |
コンパイル時間 | 13,695 ms |
コンパイル使用メモリ | 378,180 KB |
実行使用メモリ | 42,000 KB |
最終ジャッジ日時 | 2024-10-05 10:45:12 |
合計ジャッジ時間 | 34,061 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 0 ms
5,248 KB |
testcase_01 | AC | 0 ms
5,248 KB |
testcase_02 | AC | 1 ms
5,248 KB |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | AC | 1 ms
5,248 KB |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | RE | - |
testcase_09 | RE | - |
testcase_10 | RE | - |
testcase_11 | RE | - |
testcase_12 | RE | - |
testcase_13 | RE | - |
testcase_14 | RE | - |
testcase_15 | RE | - |
testcase_16 | RE | - |
testcase_17 | RE | - |
testcase_18 | RE | - |
testcase_19 | RE | - |
testcase_20 | RE | - |
testcase_21 | RE | - |
testcase_22 | RE | - |
testcase_23 | RE | - |
testcase_24 | RE | - |
testcase_25 | RE | - |
testcase_26 | RE | - |
testcase_27 | RE | - |
testcase_28 | RE | - |
testcase_29 | RE | - |
testcase_30 | RE | - |
testcase_31 | RE | - |
testcase_32 | RE | - |
testcase_33 | RE | - |
testcase_34 | RE | - |
testcase_35 | RE | - |
testcase_36 | RE | - |
testcase_37 | RE | - |
testcase_38 | RE | - |
testcase_39 | RE | - |
testcase_40 | RE | - |
testcase_41 | RE | - |
testcase_42 | RE | - |
testcase_43 | AC | 50 ms
42,000 KB |
testcase_44 | RE | - |
testcase_45 | RE | - |
testcase_46 | RE | - |
testcase_47 | RE | - |
testcase_48 | RE | - |
testcase_49 | RE | - |
testcase_50 | RE | - |
ソースコード
//! # Bundled libraries //! //! - `procon_reader 0.1.0 (git+https://github.com/ia7ck/rust-competitive-programming#bd4907c0d20d80d0c7a19f92b3bb682e6326d08d)` licensed under **missing** as `crate::__cargo_equip::crates::procon_reader` pub use __cargo_equip::prelude::*; use procon_reader::ProconReader; fn main() { let stdin = std::io::stdin(); let mut rd = ProconReader::new(stdin.lock()); let h: usize = rd.get(); let w: usize = rd.get(); let n: usize = rd.get(); let mut cities = Vec::new(); let mut g = vec![vec![]; h * w]; for i in 0..n { let x: usize = rd.get(); let y: usize = rd.get(); cities.push((x, y)); g[x - 1].push((h + (y - 1), i)); g[h + (y - 1)].push((x - 1, i)); } let mut seen_node = vec![false; h * w]; let mut seen_edge = vec![false; h * w]; for u in 0..(h * w) { if seen_node[u] { continue; } let mut cycle = Vec::new(); dfs(u, &g, &mut seen_node, &mut seen_edge, &mut cycle); if cycle.is_empty() { continue; } assert!(cycle.len() >= 4); cycle.reverse(); let (_, y0) = cities[cycle[0]]; let (_, y1) = cities[cycle[1]]; let (_, y2) = cities[cycle[2]]; if y0 != y1 { assert_eq!(y1, y2); cycle.rotate_left(1); } println!("{}", cycle.len()); for t in cycle { print!("{} ", t + 1); } return; } println!("-1"); } fn dfs( u: usize, g: &Vec<Vec<(usize, usize)>>, seen_node: &mut Vec<bool>, seen_edge: &mut Vec<bool>, cycle: &mut Vec<usize>, ) -> Option<usize> { seen_node[u] = true; for &(v, idx) in &g[u] { if seen_edge[idx] { continue; } seen_edge[idx] = true; if seen_node[v] { cycle.push(idx); return Some(v); } if let Some(end) = dfs(v, g, seen_node, seen_edge, cycle) { cycle.push(idx); return if u != end { Some(end) } else { None }; } } None } // The following code was expanded by `cargo-equip`. #[rustfmt::skip] #[allow(unused)] mod __cargo_equip { pub(crate) mod crates { pub mod procon_reader {use std::io::BufRead;use std::str::FromStr;pub struct ProconReader<R>{r:R,l:String,i:usize,}impl<R:BufRead>ProconReader<R>{pub fn new(reader:R)->Self{Self{r:reader,l:String::new(),i:0,}}pub fn get<T>(&mut self)->T where T:FromStr,<T as FromStr>::Err:std::fmt::Debug,{self.skip_blanks();assert!(self.i<self.l.len());assert_ne!(&self.l[self.i..=self.i]," ");let rest=&self.l[self.i..];let len=rest.find(' ').unwrap_or_else(| |rest.len());let val=rest[..len].parse().unwrap_or_else(|e|panic!("{:?}, attempt to read `{}`",e,rest));self.i+=len;val}fn skip_blanks(&mut self){loop{match self.l[self.i..].find(|ch|ch!=' '){Some(j)=>{self.i+=j;break;}None=>{let mut buf=String::new();let num_bytes=self.r.read_line(&mut buf).unwrap_or_else(|_|panic!("invalid UTF-8"));assert!(num_bytes>0,"reached EOF :(");self.l=buf.trim_end_matches('\n').trim_end_matches('\r').to_string();self.i=0;}}}}pub fn get_vec<T>(&mut self,n:usize)->Vec<T>where T:FromStr,<T as FromStr>::Err:std::fmt::Debug,{(0..n).map(|_|self.get()).collect()}pub fn get_chars(&mut self)->Vec<char>{self.get::<String>().chars().collect()}}} } pub(crate) mod macros { pub mod procon_reader {} } pub(crate) mod prelude {pub use crate::__cargo_equip::crates::*;} mod preludes { pub mod procon_reader {} } }