結果
問題 | No.1647 Travel in Mitaru city 2 |
ユーザー | koba-e964 |
提出日時 | 2021-08-17 15:41:42 |
言語 | Rust (1.77.0 + proconio) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,303 bytes |
コンパイル時間 | 12,391 ms |
コンパイル使用メモリ | 402,804 KB |
実行使用メモリ | 38,552 KB |
最終ジャッジ日時 | 2024-10-10 13:16:09 |
合計ジャッジ時間 | 21,827 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,816 KB |
testcase_01 | AC | 1 ms
6,816 KB |
testcase_02 | AC | 2 ms
6,816 KB |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | AC | 1 ms
6,820 KB |
testcase_06 | AC | 1 ms
6,816 KB |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | AC | 63 ms
22,952 KB |
testcase_13 | AC | 60 ms
25,488 KB |
testcase_14 | WA | - |
testcase_15 | AC | 66 ms
34,588 KB |
testcase_16 | AC | 67 ms
32,700 KB |
testcase_17 | AC | 57 ms
26,196 KB |
testcase_18 | AC | 54 ms
25,324 KB |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | AC | 75 ms
36,764 KB |
testcase_24 | AC | 69 ms
31,256 KB |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | AC | 73 ms
38,552 KB |
testcase_29 | WA | - |
testcase_30 | AC | 72 ms
35,616 KB |
testcase_31 | WA | - |
testcase_32 | AC | 70 ms
36,992 KB |
testcase_33 | AC | 68 ms
33,124 KB |
testcase_34 | AC | 79 ms
37,852 KB |
testcase_35 | AC | 70 ms
33,596 KB |
testcase_36 | WA | - |
testcase_37 | AC | 75 ms
37,664 KB |
testcase_38 | AC | 74 ms
29,656 KB |
testcase_39 | AC | 65 ms
24,600 KB |
testcase_40 | AC | 63 ms
29,776 KB |
testcase_41 | WA | - |
testcase_42 | AC | 65 ms
28,784 KB |
testcase_43 | AC | 1 ms
6,816 KB |
testcase_44 | AC | 4 ms
6,816 KB |
testcase_45 | WA | - |
testcase_46 | AC | 53 ms
18,132 KB |
testcase_47 | WA | - |
testcase_48 | WA | - |
testcase_49 | WA | - |
testcase_50 | WA | - |
ソースコード
#[allow(unused_imports)] use std::cmp::*; #[allow(unused_imports)] use std::collections::*; use std::io::{Write, BufWriter}; // https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 macro_rules! input { ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes.by_ref().map(|r|r.unwrap() as char) .skip_while(|c|c.is_whitespace()) .take_while(|c|!c.is_whitespace()) .collect() }; input_inner!{next, $($r)*} }; } macro_rules! input_inner { ($next:expr) => {}; ($next:expr,) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} }; } macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ($(read_value!($next, $t)),*) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, usize1) => (read_value!($next, usize) - 1); ($next:expr, [ $t:tt ]) => {{ let len = read_value!($next, usize); read_value!($next, [$t; len]) }}; ($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error")); } trait Change { fn chmax(&mut self, x: Self); fn chmin(&mut self, x: Self); } impl<T: PartialOrd> Change for T { fn chmax(&mut self, x: T) { if *self < x { *self = x; } } fn chmin(&mut self, x: T) { if *self > x { *self = x; } } } fn main() { // In order to avoid potential stack overflow, spawn a new thread. let stack_size = 104_857_600; // 100 MB let thd = std::thread::Builder::new().stack_size(stack_size); thd.spawn(|| solve()).unwrap().join().unwrap(); } fn dfs(v: usize, par: usize, vis: &mut [bool], g: &[Vec<(usize, usize)>], ) -> Result<(), (bool, usize, Vec<usize>)> { if vis[v] { return Err((true, v, vec![])); } vis[v] = true; for &(w, idx) in &g[v] { if w == par { continue; } let sub = dfs(w, v, vis, g); if let Err((extending, orig, mut sub)) = sub { if extending { sub.push(idx + 1); } return Err((extending && orig != v, orig, sub)); } } Ok(()) } fn solve() { let out = std::io::stdout(); let mut out = BufWriter::new(out.lock()); macro_rules! puts {($($format:tt)*) => (let _ = write!(out,$($format)*););} #[allow(unused)] macro_rules! putvec { ($v:expr) => { for i in 0..$v.len() { puts!("{}{}", $v[i], if i + 1 == $v.len() {"\n"} else {" "}); } } } input! { h: usize, w: usize, n: usize, xy: [(usize1, usize1); n], } let mut g = vec![vec![]; h + w]; for i in 0..n { let (x, y) = xy[i]; g[x].push((h + y, i)); g[h + y].push((x, i)); } let mut vis = vec![false; h + w]; let res = dfs(0, h + w, &mut vis, &g); if let Err((_, _, path)) = res { puts!("{}\n", path.len()); putvec!(path); } else { puts!("-1\n"); } }