結果
問題 | No.1254 補強への架け橋 |
ユーザー | akakimidori |
提出日時 | 2020-10-09 22:18:44 |
言語 | Rust (1.77.0 + proconio) |
結果 |
AC
|
実行時間 | 62 ms / 2,000 ms |
コード長 | 3,972 bytes |
コンパイル時間 | 12,509 ms |
コンパイル使用メモリ | 378,564 KB |
実行使用メモリ | 19,536 KB |
最終ジャッジ日時 | 2024-07-20 12:18:59 |
合計ジャッジ時間 | 21,267 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 1 ms
5,248 KB |
testcase_02 | AC | 1 ms
5,376 KB |
testcase_03 | AC | 1 ms
5,376 KB |
testcase_04 | AC | 1 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 | 0 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 | 1 ms
5,376 KB |
testcase_14 | AC | 0 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 | 0 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 | 0 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 | 0 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 | 1 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 | 0 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 | 4 ms
5,376 KB |
testcase_64 | AC | 1 ms
5,376 KB |
testcase_65 | AC | 3 ms
5,376 KB |
testcase_66 | AC | 3 ms
5,376 KB |
testcase_67 | AC | 2 ms
5,376 KB |
testcase_68 | AC | 3 ms
5,376 KB |
testcase_69 | AC | 3 ms
5,376 KB |
testcase_70 | AC | 2 ms
5,376 KB |
testcase_71 | AC | 2 ms
5,376 KB |
testcase_72 | AC | 2 ms
5,376 KB |
testcase_73 | AC | 2 ms
5,376 KB |
testcase_74 | AC | 2 ms
5,376 KB |
testcase_75 | AC | 2 ms
5,376 KB |
testcase_76 | AC | 1 ms
5,376 KB |
testcase_77 | AC | 2 ms
5,376 KB |
testcase_78 | AC | 3 ms
5,376 KB |
testcase_79 | AC | 3 ms
5,376 KB |
testcase_80 | AC | 3 ms
5,376 KB |
testcase_81 | AC | 4 ms
5,376 KB |
testcase_82 | AC | 4 ms
5,376 KB |
testcase_83 | AC | 33 ms
17,280 KB |
testcase_84 | AC | 31 ms
16,896 KB |
testcase_85 | AC | 20 ms
11,520 KB |
testcase_86 | AC | 27 ms
14,976 KB |
testcase_87 | AC | 31 ms
16,128 KB |
testcase_88 | AC | 6 ms
5,376 KB |
testcase_89 | AC | 36 ms
17,152 KB |
testcase_90 | AC | 20 ms
11,776 KB |
testcase_91 | AC | 15 ms
9,728 KB |
testcase_92 | AC | 9 ms
6,144 KB |
testcase_93 | AC | 23 ms
14,336 KB |
testcase_94 | AC | 24 ms
13,312 KB |
testcase_95 | AC | 24 ms
13,184 KB |
testcase_96 | AC | 35 ms
16,512 KB |
testcase_97 | AC | 13 ms
8,704 KB |
testcase_98 | AC | 33 ms
16,640 KB |
testcase_99 | AC | 18 ms
11,008 KB |
testcase_100 | AC | 39 ms
17,664 KB |
testcase_101 | AC | 8 ms
5,760 KB |
testcase_102 | AC | 4 ms
5,376 KB |
testcase_103 | AC | 10 ms
6,272 KB |
testcase_104 | AC | 12 ms
7,552 KB |
testcase_105 | AC | 27 ms
14,208 KB |
testcase_106 | AC | 13 ms
9,344 KB |
testcase_107 | AC | 36 ms
17,280 KB |
testcase_108 | AC | 34 ms
17,152 KB |
testcase_109 | AC | 25 ms
14,080 KB |
testcase_110 | AC | 23 ms
12,928 KB |
testcase_111 | AC | 25 ms
13,696 KB |
testcase_112 | AC | 11 ms
7,296 KB |
testcase_113 | AC | 22 ms
12,672 KB |
testcase_114 | AC | 14 ms
9,088 KB |
testcase_115 | AC | 5 ms
5,376 KB |
testcase_116 | AC | 17 ms
9,984 KB |
testcase_117 | AC | 10 ms
7,424 KB |
testcase_118 | AC | 32 ms
16,256 KB |
testcase_119 | AC | 18 ms
10,880 KB |
testcase_120 | AC | 31 ms
15,872 KB |
testcase_121 | AC | 9 ms
6,528 KB |
testcase_122 | AC | 16 ms
10,112 KB |
testcase_123 | AC | 1 ms
5,376 KB |
testcase_124 | AC | 62 ms
19,404 KB |
testcase_125 | AC | 62 ms
19,536 KB |
ソースコード
//---------- begin union_find ---------- pub struct DSU { p: Vec<i32>, } impl DSU { pub fn new(n: usize) -> DSU { DSU { p: vec![-1; n] } } pub fn init(&mut self) { for p in self.p.iter_mut() { *p = -1; } } pub fn root(&self, mut x: usize) -> usize { assert!(x < self.p.len()); while self.p[x] >= 0 { x = self.p[x] as usize; } x } pub fn same(&self, x: usize, y: usize) -> bool { assert!(x < self.p.len()); assert!(y < self.p.len()); self.root(x) == self.root(y) } pub fn unite(&mut self, x: usize, y: usize) -> Option<(usize, usize)> { assert!(x < self.p.len()); assert!(y < self.p.len()); let mut x = self.root(x); let mut y = self.root(y); if x == y { return None; } if self.p[x] > self.p[y] { std::mem::swap(&mut x, &mut y); } self.p[x] += self.p[y]; self.p[y] = x as i32; Some((x, y)) } pub fn parent(&self, x: usize) -> Option<usize> { assert!(x < self.p.len()); let p = self.p[x]; if p >= 0 { Some(p as usize) } else { None } } pub fn size(&self, x: usize) -> usize { assert!(x < self.p.len()); let r = self.root(x); (-self.p[r]) as usize } } //---------- end union_find ---------- //https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); input_inner!{iter, $($r)*} }; ($($r:tt)*) => { let s = { use std::io::Read; let mut s = String::new(); std::io::stdin().read_to_string(&mut s).unwrap(); s }; let mut iter = s.split_whitespace(); input_inner!{iter, $($r)*} }; } macro_rules! input_inner { ($iter:expr) => {}; ($iter:expr, ) => {}; ($iter:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($iter, $t); input_inner!{$iter $($r)*} }; } macro_rules! read_value { ($iter:expr, ( $($t:tt),* )) => { ( $(read_value!($iter, $t)),* ) }; ($iter:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>() }; ($iter:expr, chars) => { read_value!($iter, String).chars().collect::<Vec<char>>() }; ($iter:expr, bytes) => { read_value!($iter, String).bytes().collect::<Vec<u8>>() }; ($iter:expr, usize1) => { read_value!($iter, usize) - 1 }; ($iter:expr, $t:ty) => { $iter.next().unwrap().parse::<$t>().expect("Parse error") }; } // fn run() { input! { n: usize, e: [(usize1, usize1); n], } let mut dsu = DSU::new(n); let mut g = vec![vec![]; n]; let mut back = (0, 0, 0); for (i, &(a, b)) in e.iter().enumerate() { if dsu.unite(a, b).is_some() { g[a].push((b, i)); g[b].push((a, i)); } else { back = (a, b, i); } } let mut depth = vec![0; n]; let mut parent = vec![(n, n); n]; let mut topo = vec![0]; for i in 0..n { let v = topo[i]; for &(u, k) in g[v].iter() { if u == parent[v].0 { continue; } parent[u] = (v, k); depth[u] = depth[v] + 1; topo.push(u); } } let (mut x, mut y, k) = back; let mut ans = vec![k]; while x != y { if depth[x] < depth[y] { std::mem::swap(&mut x, &mut y); } ans.push(parent[x].1); x = parent[x].0; } ans.sort(); let mut s = String::from(&format!("{}\n", ans.len())); for a in ans { s.push_str(&format!("{} ", a + 1)); } s.pop(); println!("{}", s); } fn main() { run(); }