結果

問題 No.1254 補強への架け橋
ユーザー StrorkisStrorkis
提出日時 2020-10-10 12:10:50
言語 Rust
(1.77.0)
結果
AC  
実行時間 93 ms / 2,000 ms
コード長 2,376 bytes
コンパイル時間 1,182 ms
コンパイル使用メモリ 150,008 KB
実行使用メモリ 31,768 KB
最終ジャッジ日時 2023-09-27 21:22:39
合計ジャッジ時間 12,659 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 0 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 0 ms
4,376 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 0 ms
4,380 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 1 ms
4,380 KB
testcase_34 AC 1 ms
4,380 KB
testcase_35 AC 1 ms
4,376 KB
testcase_36 AC 1 ms
4,376 KB
testcase_37 AC 1 ms
4,376 KB
testcase_38 AC 1 ms
4,376 KB
testcase_39 AC 1 ms
4,380 KB
testcase_40 AC 1 ms
4,376 KB
testcase_41 AC 1 ms
4,376 KB
testcase_42 AC 1 ms
4,376 KB
testcase_43 AC 1 ms
4,376 KB
testcase_44 AC 1 ms
4,376 KB
testcase_45 AC 1 ms
4,380 KB
testcase_46 AC 1 ms
4,380 KB
testcase_47 AC 1 ms
4,380 KB
testcase_48 AC 1 ms
4,380 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 2 ms
4,380 KB
testcase_54 AC 2 ms
4,380 KB
testcase_55 AC 1 ms
4,380 KB
testcase_56 AC 1 ms
4,376 KB
testcase_57 AC 1 ms
4,380 KB
testcase_58 AC 1 ms
4,376 KB
testcase_59 AC 1 ms
4,376 KB
testcase_60 AC 1 ms
4,380 KB
testcase_61 AC 1 ms
4,380 KB
testcase_62 AC 1 ms
4,376 KB
testcase_63 AC 4 ms
4,376 KB
testcase_64 AC 2 ms
4,376 KB
testcase_65 AC 4 ms
4,376 KB
testcase_66 AC 3 ms
4,380 KB
testcase_67 AC 1 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 1 ms
4,380 KB
testcase_72 AC 4 ms
4,380 KB
testcase_73 AC 2 ms
4,380 KB
testcase_74 AC 4 ms
4,380 KB
testcase_75 AC 3 ms
4,376 KB
testcase_76 AC 1 ms
4,376 KB
testcase_77 AC 2 ms
4,376 KB
testcase_78 AC 4 ms
4,376 KB
testcase_79 AC 5 ms
4,376 KB
testcase_80 AC 4 ms
4,380 KB
testcase_81 AC 5 ms
4,376 KB
testcase_82 AC 4 ms
4,380 KB
testcase_83 AC 65 ms
14,140 KB
testcase_84 AC 63 ms
13,780 KB
testcase_85 AC 31 ms
9,400 KB
testcase_86 AC 44 ms
12,332 KB
testcase_87 AC 56 ms
13,308 KB
testcase_88 AC 7 ms
4,376 KB
testcase_89 AC 58 ms
14,296 KB
testcase_90 AC 30 ms
9,720 KB
testcase_91 AC 23 ms
8,192 KB
testcase_92 AC 12 ms
5,336 KB
testcase_93 AC 47 ms
11,932 KB
testcase_94 AC 36 ms
11,004 KB
testcase_95 AC 38 ms
10,988 KB
testcase_96 AC 52 ms
13,516 KB
testcase_97 AC 19 ms
7,344 KB
testcase_98 AC 59 ms
13,544 KB
testcase_99 AC 31 ms
9,148 KB
testcase_100 AC 62 ms
14,296 KB
testcase_101 AC 10 ms
5,148 KB
testcase_102 AC 6 ms
4,376 KB
testcase_103 AC 13 ms
5,372 KB
testcase_104 AC 17 ms
6,584 KB
testcase_105 AC 43 ms
11,896 KB
testcase_106 AC 20 ms
7,864 KB
testcase_107 AC 57 ms
14,072 KB
testcase_108 AC 61 ms
13,940 KB
testcase_109 AC 42 ms
11,696 KB
testcase_110 AC 37 ms
10,932 KB
testcase_111 AC 45 ms
11,436 KB
testcase_112 AC 16 ms
6,236 KB
testcase_113 AC 33 ms
10,412 KB
testcase_114 AC 19 ms
7,760 KB
testcase_115 AC 8 ms
4,380 KB
testcase_116 AC 25 ms
8,500 KB
testcase_117 AC 16 ms
6,348 KB
testcase_118 AC 53 ms
13,476 KB
testcase_119 AC 27 ms
9,056 KB
testcase_120 AC 54 ms
12,976 KB
testcase_121 AC 13 ms
5,704 KB
testcase_122 AC 24 ms
8,400 KB
testcase_123 AC 1 ms
4,376 KB
testcase_124 AC 88 ms
31,632 KB
testcase_125 AC 93 ms
31,768 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

fn read<T: std::str::FromStr>() -> 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<T: std::fmt::Display>(v: Vec<T>, s: &str) -> String {
    v.iter().map(|x| x.to_string()).collect::<Vec<_>>().join(s)
}

use std::cmp::min;

struct LowLink {
    g: Vec<Vec<(usize, usize)>>,
    used: Vec<bool>,
    ord: Vec<usize>, low: Vec<usize>,
    bridges: Vec<usize>,
}

impl LowLink {
    fn new(n: usize, g: Vec<Vec<(usize, usize)>>) -> 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::<usize>();

    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::<Vec<_>>();
    println!("{}", non_bridges.len());
    println!("{}", vec_to_string(non_bridges, " "));
}
0