fn read() -> T { let mut input = String::new(); std::io::stdin().read_line(&mut input).unwrap(); input.trim_end().parse().ok().unwrap() } macro_rules! read_to_tuple { ( $( $t:ty ),* ) => {{ let mut input = String::new(); std::io::stdin().read_line(&mut input).unwrap(); let mut iter = input.split_whitespace(); ( $( iter.next().unwrap().parse::<$t>().unwrap() ),* ) }}; } fn vec_to_string(v: Vec, s: &str) -> String { v.iter().map(|x| x.to_string()).collect::>().join(s) } use std::cmp::min; struct LowLink { g: Vec>, used: Vec, ord: Vec, low: Vec, bridges: Vec, } impl LowLink { fn new(n: usize, g: Vec>) -> LowLink { let mut low_link = LowLink { g, used: vec![false; n], ord: vec![0; n], low: vec![0; n], bridges: Vec::new(), }; let mut k = 0; for i in 0..n { if low_link.used[i] { continue; } low_link.dfs(i, !0, &mut k); } low_link } fn dfs(&mut self, from: usize, par: usize, k: &mut usize) { self.used[from] = true; self.ord[from] = *k; *k += 1; self.low[from] = self.ord[from]; for (to, i) in self.g[from].clone() { if !self.used[to] { self.dfs(to, from, k); self.low[from] = min(self.low[from], self.low[to]); if self.ord[from] < self.low[to] { self.bridges.push(i); } } else if to != par { self.low[from] = min(self.low[from], self.ord[to]); } } } } fn main() { let n = read::(); let mut g = vec![vec![]; n]; for i in 1..=n { let (from, to) = read_to_tuple!(usize, usize); let (from, to) = (from - 1, to - 1); g[from].push((to, i)); g[to].push((from, i)); } let low_link = LowLink::new(n, g); let mut is_bridge = vec![false; n + 1]; for bridge in low_link.bridges { is_bridge[bridge] = true; } let non_bridges = (1..=n).filter(|&i| !is_bridge[i]).collect::>(); println!("{}", non_bridges.len()); println!("{}", vec_to_string(non_bridges, " ")); }