find vertices in G that are reachable from sources
(graph: &dyn IGraph, sources: &[usize])
| 16 | |
| 17 | /// find vertices in G that are reachable from sources |
| 18 | pub fn new_multi(graph: &dyn IGraph, sources: &[usize]) -> Self { |
| 19 | let mut dfs = Self { |
| 20 | marked: vec![false; graph.V()], |
| 21 | }; |
| 22 | for &s in sources { |
| 23 | if !dfs.marked[s] { |
| 24 | dfs.dfs(graph, s); |
| 25 | } |
| 26 | } |
| 27 | dfs |
| 28 | } |
| 29 | |
| 30 | /// is v reachable? |
| 31 | pub fn marked(&self, v: usize) -> bool { |