結果
問題 | No.1254 補強への架け橋 |
ユーザー | o2c |
提出日時 | 2020-10-09 23:46:41 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 175 ms / 2,000 ms |
コード長 | 3,865 bytes |
コンパイル時間 | 13,477 ms |
コンパイル使用メモリ | 377,596 KB |
実行使用メモリ | 33,024 KB |
最終ジャッジ日時 | 2024-07-20 14:37:22 |
合計ジャッジ時間 | 23,491 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 1 ms
5,248 KB |
testcase_02 | AC | 0 ms
5,376 KB |
testcase_03 | AC | 1 ms
5,376 KB |
testcase_04 | AC | 0 ms
5,376 KB |
testcase_05 | AC | 1 ms
5,376 KB |
testcase_06 | AC | 1 ms
5,376 KB |
testcase_07 | AC | 1 ms
5,376 KB |
testcase_08 | AC | 1 ms
5,376 KB |
testcase_09 | AC | 1 ms
5,376 KB |
testcase_10 | AC | 1 ms
5,376 KB |
testcase_11 | AC | 1 ms
5,376 KB |
testcase_12 | AC | 1 ms
5,376 KB |
testcase_13 | AC | 0 ms
5,376 KB |
testcase_14 | AC | 1 ms
5,376 KB |
testcase_15 | AC | 1 ms
5,376 KB |
testcase_16 | AC | 1 ms
5,376 KB |
testcase_17 | AC | 1 ms
5,376 KB |
testcase_18 | AC | 1 ms
5,376 KB |
testcase_19 | AC | 1 ms
5,376 KB |
testcase_20 | AC | 1 ms
5,376 KB |
testcase_21 | AC | 1 ms
5,376 KB |
testcase_22 | AC | 1 ms
5,376 KB |
testcase_23 | AC | 1 ms
5,376 KB |
testcase_24 | AC | 1 ms
5,376 KB |
testcase_25 | AC | 1 ms
5,376 KB |
testcase_26 | AC | 1 ms
5,376 KB |
testcase_27 | AC | 1 ms
5,376 KB |
testcase_28 | AC | 1 ms
5,376 KB |
testcase_29 | AC | 1 ms
5,376 KB |
testcase_30 | AC | 1 ms
5,376 KB |
testcase_31 | AC | 1 ms
5,376 KB |
testcase_32 | AC | 1 ms
5,376 KB |
testcase_33 | AC | 1 ms
5,376 KB |
testcase_34 | AC | 1 ms
5,376 KB |
testcase_35 | AC | 1 ms
5,376 KB |
testcase_36 | AC | 1 ms
5,376 KB |
testcase_37 | AC | 1 ms
5,376 KB |
testcase_38 | AC | 1 ms
5,376 KB |
testcase_39 | AC | 1 ms
5,376 KB |
testcase_40 | AC | 1 ms
5,376 KB |
testcase_41 | AC | 1 ms
5,376 KB |
testcase_42 | AC | 1 ms
5,376 KB |
testcase_43 | AC | 1 ms
5,376 KB |
testcase_44 | AC | 1 ms
5,376 KB |
testcase_45 | AC | 1 ms
5,376 KB |
testcase_46 | AC | 1 ms
5,376 KB |
testcase_47 | AC | 1 ms
5,376 KB |
testcase_48 | AC | 1 ms
5,376 KB |
testcase_49 | AC | 1 ms
5,376 KB |
testcase_50 | AC | 2 ms
5,376 KB |
testcase_51 | AC | 1 ms
5,376 KB |
testcase_52 | AC | 1 ms
5,376 KB |
testcase_53 | AC | 1 ms
5,376 KB |
testcase_54 | AC | 1 ms
5,376 KB |
testcase_55 | AC | 1 ms
5,376 KB |
testcase_56 | AC | 1 ms
5,376 KB |
testcase_57 | AC | 1 ms
5,376 KB |
testcase_58 | AC | 1 ms
5,376 KB |
testcase_59 | AC | 1 ms
5,376 KB |
testcase_60 | AC | 1 ms
5,376 KB |
testcase_61 | AC | 1 ms
5,376 KB |
testcase_62 | AC | 1 ms
5,376 KB |
testcase_63 | AC | 7 ms
5,376 KB |
testcase_64 | AC | 2 ms
5,376 KB |
testcase_65 | AC | 4 ms
5,376 KB |
testcase_66 | AC | 4 ms
5,376 KB |
testcase_67 | AC | 2 ms
5,376 KB |
testcase_68 | AC | 4 ms
5,376 KB |
testcase_69 | AC | 6 ms
5,376 KB |
testcase_70 | AC | 3 ms
5,376 KB |
testcase_71 | AC | 2 ms
5,376 KB |
testcase_72 | AC | 5 ms
5,376 KB |
testcase_73 | AC | 2 ms
5,376 KB |
testcase_74 | AC | 5 ms
5,376 KB |
testcase_75 | AC | 4 ms
5,376 KB |
testcase_76 | AC | 2 ms
5,376 KB |
testcase_77 | AC | 3 ms
5,376 KB |
testcase_78 | AC | 6 ms
5,376 KB |
testcase_79 | AC | 7 ms
5,376 KB |
testcase_80 | AC | 6 ms
5,376 KB |
testcase_81 | AC | 6 ms
5,376 KB |
testcase_82 | AC | 6 ms
5,376 KB |
testcase_83 | AC | 102 ms
17,024 KB |
testcase_84 | AC | 85 ms
16,768 KB |
testcase_85 | AC | 42 ms
11,008 KB |
testcase_86 | AC | 71 ms
14,592 KB |
testcase_87 | AC | 76 ms
15,872 KB |
testcase_88 | AC | 10 ms
5,376 KB |
testcase_89 | AC | 95 ms
16,768 KB |
testcase_90 | AC | 49 ms
11,776 KB |
testcase_91 | AC | 37 ms
9,600 KB |
testcase_92 | AC | 17 ms
6,016 KB |
testcase_93 | AC | 61 ms
13,952 KB |
testcase_94 | AC | 60 ms
13,056 KB |
testcase_95 | AC | 59 ms
12,928 KB |
testcase_96 | AC | 89 ms
16,000 KB |
testcase_97 | AC | 30 ms
8,576 KB |
testcase_98 | AC | 76 ms
16,256 KB |
testcase_99 | AC | 45 ms
10,752 KB |
testcase_100 | AC | 84 ms
17,280 KB |
testcase_101 | AC | 16 ms
5,632 KB |
testcase_102 | AC | 9 ms
5,376 KB |
testcase_103 | AC | 18 ms
5,888 KB |
testcase_104 | AC | 25 ms
7,424 KB |
testcase_105 | AC | 63 ms
13,952 KB |
testcase_106 | AC | 33 ms
9,088 KB |
testcase_107 | AC | 88 ms
16,896 KB |
testcase_108 | AC | 82 ms
16,768 KB |
testcase_109 | AC | 70 ms
13,824 KB |
testcase_110 | AC | 49 ms
12,800 KB |
testcase_111 | AC | 63 ms
13,440 KB |
testcase_112 | AC | 25 ms
7,168 KB |
testcase_113 | AC | 60 ms
12,416 KB |
testcase_114 | AC | 34 ms
8,960 KB |
testcase_115 | AC | 11 ms
5,376 KB |
testcase_116 | AC | 40 ms
9,984 KB |
testcase_117 | AC | 25 ms
7,168 KB |
testcase_118 | AC | 80 ms
16,128 KB |
testcase_119 | AC | 49 ms
10,624 KB |
testcase_120 | AC | 75 ms
15,616 KB |
testcase_121 | AC | 19 ms
6,528 KB |
testcase_122 | AC | 33 ms
9,728 KB |
testcase_123 | AC | 1 ms
5,376 KB |
testcase_124 | AC | 171 ms
33,024 KB |
testcase_125 | AC | 175 ms
32,896 KB |
ソースコード
#![allow(unused_imports)] use {std::cmp::*, std::collections::*, std::io::Write, std::ops::*}; #[allow(unused_macros)] macro_rules !dbg {($($e :expr ) ,*) =>{#[cfg (debug_assertions ) ] $({let (e ,mut err ) =(stringify !($e ) ,std ::io ::stderr () ) ;writeln !(err ,"{} = {:?}" ,e ,$e ) .unwrap () } ) *} ;} #[allow(unused_macros)] macro_rules !min {($a :expr $(,) *) =>{{$a } } ;($a :expr ,$b :expr $(,) *) =>{{std ::cmp ::min ($a ,$b ) } } ;($a :expr ,$($rest :expr ) ,+$(,) *) =>{{std ::cmp ::min ($a ,min !($($rest ) ,+) ) } } ;} #[allow(unused_macros)] macro_rules !chmin {($base :expr ,$($cmps :expr ) ,+$(,) *) =>{{let cmp_min =min !($($cmps ) ,+) ;if $base >cmp_min {$base =cmp_min ;true } else {false } } } ;} #[allow(unused_macros)] macro_rules !max {($a :expr $(,) *) =>{{$a } } ;($a :expr ,$b :expr $(,) *) =>{{std ::cmp ::max ($a ,$b ) } } ;($a :expr ,$($rest :expr ) ,+$(,) *) =>{{std ::cmp ::max ($a ,max !($($rest ) ,+) ) } } ;} #[allow(unused_macros)] macro_rules !chmax {($base :expr ,$($cmps :expr ) ,+$(,) *) =>{{let cmp_max =max !($($cmps ) ,+) ;if $base <cmp_max {$base =cmp_max ;true } else {false } } } ;} #[allow(dead_code)] mod scanner { use std; use std::io::Read; use std::str::FromStr; use std::str::SplitWhitespace; pub struct Scanner<'a> { it: SplitWhitespace<'a>, } impl<'a> Scanner<'a> { pub fn new(s: &'a String) -> Scanner<'a> { Scanner { it: s.split_whitespace(), } } pub fn next<T: FromStr>(&mut self) -> T { match self.it.next().unwrap().parse::<T>() { Ok(v) => v, _ => panic!("Scanner error"), } } pub fn next_chars(&mut self) -> Vec<char> { self.next::<String>().chars().collect() } pub fn next_vec<T: FromStr>(&mut self, len: usize) -> Vec<T> { (0..len).map(|_| self.next()).collect() } } pub fn read_string() -> String { let mut s = String::new(); std::io::stdin().read_to_string(&mut s).unwrap(); s } } fn main() { let sc = scanner::read_string(); let mut sc = scanner::Scanner::new(&sc); let out = std::io::stdout(); let mut out = std::io::BufWriter::new(out.lock()); let n: usize = sc.next(); let mut map = std::collections::BTreeMap::<(usize, usize), usize>::new(); let mut to = vec![vec![]; n]; for i in 0..n { let a = sc.next::<usize>() - 1; let b = sc.next::<usize>() - 1; to[a].push(b); to[b].push(a); map.insert((a, b), i); map.insert((b, a), i); } let mut stack = vec![]; let mut node = vec![]; let mut set = std::collections::BTreeSet::<usize>::new(); dfs(0, 0, &to, &mut set, &mut stack, &mut node); let mut ans = vec![]; for a in node.windows(2) { ans.push(map.get(&(a[0], a[1])).unwrap()); } ans.push(map.get(&(node[0], node[node.len() - 1])).unwrap()); writeln!(out, "{}", ans.len()).unwrap(); for i in 0..ans.len() { if i != 0 { write!(out, " ").unwrap(); } write!(out, "{}", ans[i] + 1).unwrap(); } writeln!(out, "").unwrap(); } fn dfs( u: usize, p: usize, to: &Vec<Vec<usize>>, set: &mut BTreeSet<usize>, stack: &mut Vec<usize>, ans: &mut Vec<usize>, ) -> bool { stack.push(u); set.insert(u); for &v in to[u].iter() { if v == p { continue; } if set.contains(&v) { while let Some(x) = stack.pop() { ans.push(x); if x == v { break; } } return true; } if dfs(v, u, to, set, stack, ans) { return true; } } stack.pop(); set.remove(&u); false }