pub struct SccGraph { /* private fields */ }
Expand description
An SccGraph
is a directed graph that calculates strongly connected components (SCC) in $O(|V| + |E|)$.
§Example
use ac_library::SccGraph;
use proconio::{input, source::once::OnceSource};
input! {
from OnceSource::from(
"5\n\
5\n\
0 1\n\
1 2\n\
2 0\n\
0 3\n\
3 4\n",
),
n: usize,
abs: [(usize, usize)],
}
let mut graph = SccGraph::new(n);
for (a, b) in abs {
graph.add_edge(a, b);
}
assert_eq!(graph.scc(), [&[0, 1, 2][..], &[3], &[4]]);
Implementations§
Source§impl SccGraph
impl SccGraph
Sourcepub fn scc(&self) -> Vec<Vec<usize>>
pub fn scc(&self) -> Vec<Vec<usize>>
Calculates the strongly connected components (SCC) of directed graphs in $O(|V| + |E|)$.
Returns the list of the “list of the vertices” that satisfies the following.
- Each vertex is in exactly one “list of the vertices”.
- Each “list of the vertices” corresponds to the vertex set of a strongly connected component. The order of the vertices in the list is undefined.
- The list of “list of the vertices” are sorted in topological order, i.e., for two vertices $u$, $v$ in different strongly connected components, if there is a directed path from $u$ to $v$, the list containing $u$ appears earlier than the list containing $v$.
§Complexity
- $O(n + m)$ where $m$ is the number of added edges
Trait Implementations§
Auto Trait Implementations§
impl Freeze for SccGraph
impl RefUnwindSafe for SccGraph
impl Send for SccGraph
impl Sync for SccGraph
impl Unpin for SccGraph
impl UnwindSafe for SccGraph
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more