結果

問題 No.1254 補強への架け橋
ユーザー cotton_fn_cotton_fn_
提出日時 2020-10-09 22:07:54
言語 Rust
(1.72.1)
結果
AC  
実行時間 55 ms / 2,000 ms
コード長 5,545 bytes
コンパイル時間 2,717 ms
コンパイル使用メモリ 165,724 KB
実行使用メモリ 24,236 KB
最終ジャッジ日時 2023-09-27 17:21:22
合計ジャッジ時間 11,124 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 1 ms
4,376 KB
testcase_33 AC 1 ms
4,376 KB
testcase_34 AC 1 ms
4,376 KB
testcase_35 AC 2 ms
4,380 KB
testcase_36 AC 1 ms
4,376 KB
testcase_37 AC 1 ms
4,380 KB
testcase_38 AC 1 ms
4,376 KB
testcase_39 AC 1 ms
4,380 KB
testcase_40 AC 1 ms
4,380 KB
testcase_41 AC 1 ms
4,376 KB
testcase_42 AC 1 ms
4,380 KB
testcase_43 AC 1 ms
4,380 KB
testcase_44 AC 1 ms
4,380 KB
testcase_45 AC 1 ms
4,376 KB
testcase_46 AC 1 ms
4,380 KB
testcase_47 AC 1 ms
4,376 KB
testcase_48 AC 1 ms
4,376 KB
testcase_49 AC 1 ms
4,376 KB
testcase_50 AC 1 ms
4,376 KB
testcase_51 AC 1 ms
4,376 KB
testcase_52 AC 1 ms
4,376 KB
testcase_53 AC 1 ms
4,380 KB
testcase_54 AC 1 ms
4,376 KB
testcase_55 AC 1 ms
4,376 KB
testcase_56 AC 1 ms
4,380 KB
testcase_57 AC 2 ms
4,380 KB
testcase_58 AC 1 ms
4,376 KB
testcase_59 AC 1 ms
4,380 KB
testcase_60 AC 1 ms
4,380 KB
testcase_61 AC 1 ms
4,376 KB
testcase_62 AC 1 ms
4,380 KB
testcase_63 AC 4 ms
4,376 KB
testcase_64 AC 2 ms
4,380 KB
testcase_65 AC 3 ms
4,376 KB
testcase_66 AC 3 ms
4,380 KB
testcase_67 AC 2 ms
4,380 KB
testcase_68 AC 3 ms
4,376 KB
testcase_69 AC 4 ms
4,376 KB
testcase_70 AC 2 ms
4,376 KB
testcase_71 AC 2 ms
4,376 KB
testcase_72 AC 3 ms
4,376 KB
testcase_73 AC 2 ms
4,376 KB
testcase_74 AC 4 ms
4,380 KB
testcase_75 AC 3 ms
4,376 KB
testcase_76 AC 2 ms
4,380 KB
testcase_77 AC 2 ms
4,380 KB
testcase_78 AC 4 ms
4,376 KB
testcase_79 AC 4 ms
4,376 KB
testcase_80 AC 3 ms
4,376 KB
testcase_81 AC 4 ms
4,380 KB
testcase_82 AC 4 ms
4,380 KB
testcase_83 AC 38 ms
10,692 KB
testcase_84 AC 37 ms
10,436 KB
testcase_85 AC 22 ms
6,984 KB
testcase_86 AC 29 ms
9,032 KB
testcase_87 AC 35 ms
9,820 KB
testcase_88 AC 5 ms
4,376 KB
testcase_89 AC 37 ms
10,660 KB
testcase_90 AC 23 ms
7,248 KB
testcase_91 AC 18 ms
5,880 KB
testcase_92 AC 10 ms
4,380 KB
testcase_93 AC 30 ms
8,812 KB
testcase_94 AC 26 ms
7,980 KB
testcase_95 AC 27 ms
8,020 KB
testcase_96 AC 35 ms
10,092 KB
testcase_97 AC 15 ms
5,180 KB
testcase_98 AC 35 ms
10,096 KB
testcase_99 AC 20 ms
6,756 KB
testcase_100 AC 36 ms
10,872 KB
testcase_101 AC 8 ms
4,376 KB
testcase_102 AC 5 ms
4,376 KB
testcase_103 AC 10 ms
4,376 KB
testcase_104 AC 13 ms
4,560 KB
testcase_105 AC 29 ms
8,752 KB
testcase_106 AC 16 ms
5,664 KB
testcase_107 AC 37 ms
10,592 KB
testcase_108 AC 38 ms
10,424 KB
testcase_109 AC 29 ms
8,756 KB
testcase_110 AC 26 ms
7,964 KB
testcase_111 AC 28 ms
8,580 KB
testcase_112 AC 12 ms
4,380 KB
testcase_113 AC 24 ms
7,720 KB
testcase_114 AC 16 ms
5,344 KB
testcase_115 AC 6 ms
4,380 KB
testcase_116 AC 18 ms
6,148 KB
testcase_117 AC 13 ms
4,380 KB
testcase_118 AC 33 ms
10,140 KB
testcase_119 AC 20 ms
6,716 KB
testcase_120 AC 33 ms
9,816 KB
testcase_121 AC 11 ms
4,376 KB
testcase_122 AC 18 ms
6,152 KB
testcase_123 AC 1 ms
4,376 KB
testcase_124 AC 54 ms
23,996 KB
testcase_125 AC 55 ms
24,236 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#![allow(unused_imports, unused_macros)]

use kyoproio::*;
use std::{
    collections::*,
    io::{self, prelude::*},
    iter,
    mem::{replace, swap},
};

fn main() -> io::Result<()> {
    std::thread::Builder::new()
        .stack_size(64 * 1024 * 1024)
        .spawn(|| {
            let stdin = io::stdin();
            let stdout = io::stdout();
            run(KInput::new(stdin.lock()), io::BufWriter::new(stdout.lock()))
        })?
        .join()
        .unwrap()
}

fn run<I: Input, O: Write>(mut kin: I, mut out: O) -> io::Result<()> {
    macro_rules! output { ($($args:expr),+) => { write!(&mut out, $($args),+)?; }; }
    macro_rules! outputln {
        ($($args:expr),+) => { output!($($args),+); outputln!(); };
        () => { output!("\n"); if cfg!(debug_assertions) { out.flush()?; } }
    }

    let n: usize = kin.input();
    let es: Vec<(usize, usize)> = kin.seq(n);
    let mut g = vec![Vec::new(); n + 1];
    for &(u, v) in &es {
        g[u].push(v);
        g[v].push(u);
    }
    let ll = LowLink::new(&g);
    let mut ans = Vec::new();
    for i in 0..n {
        let (u, v) = es[i];
        if !ll.is_bridge(u, v) {
            ans.push(i + 1);
        }
    }
    outputln!("{}", ans.len());
    for i in ans {
        output!("{} ", i);
    }
    outputln!();

    Ok(())
}

#[derive(Debug)]
pub struct LowLink<'a> {
    g: &'a [Vec<usize>],
    ord: Vec<usize>,
    low: Vec<usize>,
}
impl<'a> LowLink<'a> {
    pub fn new(g: &'a [Vec<usize>]) -> Self {
        let mut ll = Self {
            g,
            ord: vec![!0; g.len()],
            low: vec![!0; g.len()],
        };
        let mut id = 0;
        for u in 0..g.len() {
            if ll.ord[u] == !0 {
                ll.dfs(u, !0, &mut id);
            }
        }
        ll
    }
    fn dfs(&mut self, u: usize, p: usize, id: &mut usize) {
        self.ord[u] = *id;
        self.low[u] = *id;
        *id += 1;
        for &v in self.g[u].iter().filter(|&&v| v != p) {
            if self.ord[v] == !0 {
                self.dfs(v, u, id);
            }
            self.low[u] = self.low[u].min(self.low[v]);
        }
    }
    pub fn graph(&self) -> &[Vec<usize>] {
        &self.g
    }
    pub fn is_bridge(&self, mut u: usize, mut v: usize) -> bool {
        if self.ord[u] > self.ord[v] {
            swap(&mut u, &mut v)
        }
        self.ord[u] < self.low[v]
    }
}

// -----------------------------------------------------------------------------
pub mod kyoproio {
    use std::io::prelude::*;
    pub trait Input {
        fn str(&mut self) -> &str;
        fn input<T: InputParse>(&mut self) -> T {
            T::input(self)
        }
        fn iter<T: InputParse>(&mut self) -> Iter<T, Self> {
            Iter(self, std::marker::PhantomData)
        }
        fn seq<T: InputParse, B: std::iter::FromIterator<T>>(&mut self, n: usize) -> B {
            self.iter().take(n).collect()
        }
    }
    pub struct KInput<R> {
        src: R,
        buf: String,
        pos: usize,
    }
    impl<R: BufRead> KInput<R> {
        pub fn new(src: R) -> Self {
            Self {
                src,
                buf: String::with_capacity(1024),
                pos: 0,
            }
        }
    }
    impl<R: BufRead> Input for KInput<R> {
        fn str(&mut self) -> &str {
            loop {
                if self.pos >= self.buf.len() {
                    self.pos = 0;
                    self.buf.clear();
                    if self.src.read_line(&mut self.buf).expect("io error") == 0 {
                        return &self.buf;
                    }
                }
                let range = self.pos
                    ..self.buf[self.pos..]
                        .find(|c: char| c.is_ascii_whitespace())
                        .map(|i| i + self.pos)
                        .unwrap_or_else(|| self.buf.len());
                self.pos = range.end + 1;
                if range.end > range.start {
                    return &self.buf[range];
                }
            }
        }
    }
    pub struct Iter<'a, T, I: ?Sized>(&'a mut I, std::marker::PhantomData<*const T>);
    impl<'a, T: InputParse, I: Input + ?Sized> Iterator for Iter<'a, T, I> {
        type Item = T;
        fn next(&mut self) -> Option<T> {
            Some(self.0.input())
        }
    }
    pub trait InputParse: Sized {
        fn input<I: Input + ?Sized>(src: &mut I) -> Self;
    }
    impl InputParse for Vec<u8> {
        fn input<I: Input + ?Sized>(src: &mut I) -> Self {
            src.str().as_bytes().to_owned()
        }
    }
    macro_rules! from_str_impl {
        { $($T:ty)* } => {
            $(impl InputParse for $T {
                fn input<I: Input + ?Sized>(src: &mut I) -> Self {
                    src.str().parse::<$T>().expect("parse error")
                }
            })*
        }
    }
    from_str_impl! {
        String char bool f32 f64 isize i8 i16 i32 i64 i128 usize u8 u16 u32 u64 u128
    }
    macro_rules! tuple_impl {
        ($H:ident $($T:ident)*) => {
            impl<$H: InputParse, $($T: InputParse),*> InputParse for ($H, $($T),*) {
                fn input<I: Input + ?Sized>(src: &mut I) -> Self {
                    ($H::input(src), $($T::input(src)),*)
                }
            }
            tuple_impl!($($T)*);
        };
        () => {}
    }
    tuple_impl!(A B C D E F G);
    #[macro_export]
    macro_rules! kdbg {
        ($($v:expr),*) => {
            if cfg!(debug_assertions) { dbg!($($v),*) } else { ($($v),*) }
        }
    }
}
0