pub fn is_acyclic(&self, root: usize) -> bool {
        let mut permanent_marks: FxHashSet<usize> = FxHashSet::default();
        let mut temporary_marks: FxHashSet<usize> = FxHashSet::default();

        fn dfs_is_acyclic<V: Vertex, E: Edge>(
            graph: &Graph<V, E>,
            node: usize,
            permanent_marks: &mut FxHashSet<usize>,
            temporary_marks: &mut FxHashSet<usize>,
        ) -> bool {
            if permanent_marks.contains(&node) {
                return true;
            }
            if temporary_marks.contains(&node) {
                return false;
            }

            temporary_marks.insert(node);
            let successors_are_acyclic = graph.successors[&node].iter().all(|successor| {
                dfs_is_acyclic(graph, *successor, permanent_marks, temporary_marks)
            });
            if !successors_are_acyclic {
                return false;
            }
            temporary_marks.remove(&node);

            permanent_marks.insert(node);
            true
        }

        dfs_is_acyclic(self, root, &mut permanent_marks, &mut temporary_marks)
    }
/// Determines if the graph is acyclic
Determines if the graph is acyclic
Determines if the graph is acyclic
pub fn is_acyclic(&self, root: usize) -> bool {
        let mut permanent_marks: FxHashSet<usize> = FxHashSet::default();
        let mut temporary_marks: FxHashSet<usize> = FxHashSet::default();
        fn dfs_is_acyclic<V: Vertex, E: Edge>(
            graph: &Graph<V, E>,
            node: usize,
            permanent_marks: &mut FxHashSet<usize>,
            temporary_marks: &mut FxHashSet<usize>,
        ) -> bool {
            if permanent_marks.contains(&node) {
                return true;
            }
            if temporary_marks.contains(&node) {
                return false;
            }
            temporary_marks.insert(node);
            let successors_are_acyclic = graph.successors[&node].iter().all(|successor| {
                dfs_is_acyclic(graph, *successor, permanent_marks, temporary_marks)
            });
            if !successors_are_acyclic {
                return false;
            }
            temporary_marks.remove(&node);
            permanent_marks.insert(node);
            true
        }
        dfs_is_acyclic(self, root, &mut permanent_marks, &mut temporary_marks)
    }
pub fn is_acyclic ( & self , root : usize ) -> bool { let mut permanent_marks : FxHashSet < usize > = FxHashSet :: default ( ) ; let mut temporary_marks : FxHashSet < usize > = FxHashSet :: default ( ) ; fn dfs_is_acyclic < V : Vertex , E : Edge > ( graph : & Graph < V , E > , node : usize , permanent_marks : & mut FxHashSet < usize > , temporary_marks : & mut FxHashSet < usize > , ) -> bool { if permanent_marks . contains ( & node ) { return true ; } if temporary_marks . contains ( & node ) { return false ; } temporary_marks . insert ( node ) ; let successors_are_acyclic = graph . successors [ & node ] . iter ( ) . all ( | successor | { dfs_is_acyclic ( graph , * successor , permanent_marks , temporary_marks ) } ) ; if ! successors_are_acyclic { return false ; } temporary_marks . remove ( & node ) ; permanent_marks . insert ( node ) ; true } dfs_is_acyclic ( self , root , & mut permanent_marks , & mut temporary_marks ) }
Determines if the graph is acyclic
Determines if the graph is acyclic
&self
root
usize
&self
root
usize