結果
問題 | No.1647 Travel in Mitaru city 2 |
ユーザー | koba-e964 |
提出日時 | 2021-08-17 15:50:37 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 91 ms / 2,500 ms |
コード長 | 3,586 bytes |
コンパイル時間 | 26,865 ms |
コンパイル使用メモリ | 400,592 KB |
実行使用メモリ | 38,824 KB |
最終ジャッジ日時 | 2024-10-13 03:29:26 |
合計ジャッジ時間 | 19,897 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,820 KB |
testcase_01 | AC | 1 ms
6,816 KB |
testcase_02 | AC | 1 ms
6,816 KB |
testcase_03 | AC | 1 ms
6,816 KB |
testcase_04 | AC | 2 ms
6,816 KB |
testcase_05 | AC | 1 ms
6,816 KB |
testcase_06 | AC | 1 ms
6,820 KB |
testcase_07 | AC | 2 ms
6,816 KB |
testcase_08 | AC | 89 ms
33,664 KB |
testcase_09 | AC | 80 ms
29,784 KB |
testcase_10 | AC | 79 ms
34,344 KB |
testcase_11 | AC | 70 ms
25,040 KB |
testcase_12 | AC | 67 ms
23,472 KB |
testcase_13 | AC | 72 ms
25,840 KB |
testcase_14 | AC | 90 ms
34,792 KB |
testcase_15 | AC | 79 ms
34,568 KB |
testcase_16 | AC | 71 ms
32,780 KB |
testcase_17 | AC | 70 ms
26,032 KB |
testcase_18 | AC | 65 ms
24,120 KB |
testcase_19 | AC | 74 ms
34,868 KB |
testcase_20 | AC | 72 ms
32,104 KB |
testcase_21 | AC | 84 ms
35,732 KB |
testcase_22 | AC | 84 ms
35,852 KB |
testcase_23 | AC | 86 ms
35,776 KB |
testcase_24 | AC | 77 ms
31,248 KB |
testcase_25 | AC | 79 ms
34,356 KB |
testcase_26 | AC | 87 ms
36,324 KB |
testcase_27 | AC | 82 ms
37,076 KB |
testcase_28 | AC | 88 ms
38,436 KB |
testcase_29 | AC | 89 ms
38,824 KB |
testcase_30 | AC | 82 ms
34,532 KB |
testcase_31 | AC | 90 ms
37,684 KB |
testcase_32 | AC | 88 ms
38,196 KB |
testcase_33 | AC | 75 ms
32,060 KB |
testcase_34 | AC | 86 ms
37,428 KB |
testcase_35 | AC | 79 ms
32,904 KB |
testcase_36 | AC | 91 ms
37,852 KB |
testcase_37 | AC | 91 ms
38,552 KB |
testcase_38 | AC | 85 ms
28,916 KB |
testcase_39 | AC | 75 ms
24,824 KB |
testcase_40 | AC | 80 ms
28,348 KB |
testcase_41 | AC | 70 ms
25,092 KB |
testcase_42 | AC | 76 ms
29,196 KB |
testcase_43 | AC | 1 ms
6,816 KB |
testcase_44 | AC | 4 ms
6,820 KB |
testcase_45 | AC | 58 ms
18,276 KB |
testcase_46 | AC | 78 ms
18,204 KB |
testcase_47 | AC | 60 ms
18,284 KB |
testcase_48 | AC | 66 ms
18,240 KB |
testcase_49 | AC | 56 ms
18,296 KB |
testcase_50 | AC | 57 ms
18,376 KB |
ソースコード
#[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]; for i in 0..h { if vis[i] { continue; } let res = dfs(i, h + w, &mut vis, &g); if let Err((_, _, mut path)) = res { path.reverse(); if xy[path[0] - 1].1 != xy[path[1] - 1].1 { let u = path.pop().unwrap(); path.insert(0, u); } puts!("{}\n", path.len()); putvec!(path); return; } } puts!("-1\n"); }