From 323f08498b50e0bc6928805a949fec6e6087cbed Mon Sep 17 00:00:00 2001 From: Nagata Kana Date: Tue, 10 Dec 2024 19:56:08 +0900 Subject: [PATCH] remove dfs --- libs/dfs/Cargo.toml | 13 ------------- libs/dfs/src/lib.rs | 44 -------------------------------------------- 2 files changed, 57 deletions(-) delete mode 100644 libs/dfs/Cargo.toml delete mode 100644 libs/dfs/src/lib.rs diff --git a/libs/dfs/Cargo.toml b/libs/dfs/Cargo.toml deleted file mode 100644 index 1ffb9064..00000000 --- a/libs/dfs/Cargo.toml +++ /dev/null @@ -1,13 +0,0 @@ -[package] -name = "dfs" -version = "0.1.0" -authors = ["ngtkana "] -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] - -[dev-dependencies] -rand = { workspace = true } -randtools = { path = "../randtools" } diff --git a/libs/dfs/src/lib.rs b/libs/dfs/src/lib.rs deleted file mode 100644 index 3ad58b33..00000000 --- a/libs/dfs/src/lib.rs +++ /dev/null @@ -1,44 +0,0 @@ -use std::mem::replace; - -/// 一点からの到達可能性配列を返します。 -pub fn calc_reachability(s: usize, g: &[Vec]) -> Vec { - let mut ckd = vec![false; g.len()]; - ckd[s] = true; - let mut queue = vec![s]; - while let Some(x) = queue.pop() { - for &y in &g[x] { - if !replace(&mut ckd[y], true) { - queue.push(y); - } - } - } - ckd -} - -#[cfg(test)] -mod tests { - use super::calc_reachability; - use rand::prelude::*; - use randtools::LogUniform; - use randtools::SimpleGraph; - - // -- graph - #[test] - fn test_graph() { - let mut rng = StdRng::seed_from_u64(42); - for test_id in 0..100 { - let n = rng.sample(LogUniform(2..3000)); - let m = rng.sample(LogUniform(n - 1..(n * (n - 1) / 2 + 1).min(3000))); - println!("Test {}, n = {}, m = {}", test_id, n, m); - let g = rng.sample(SimpleGraph(n, m)); - let s = rng.gen_range(0..n); - - // calc_reachability - let ckd = calc_reachability(s, &g); - g.iter() - .enumerate() - .flat_map(|(i, v)| v.iter().map(move |&j| (i, j))) - .for_each(|(i, j)| assert_eq!(ckd[i], ckd[j])); - } - } -}