SCC

It calculates the strongly connected components of directed graphs.

Constructor

scc_graph graph(int n)

It creates a directed graph with $n$ vertices and $0$ edges.

Constraints

Complexity

add_edge

void graph.add_edge(int from, int to)

It adds a directed edge from the vertex from to the vertex to.

Constraints

Complexity

scc

vector<vector<int>> graph.scc()

It returns the list of the "list of the vertices" that satisfies the following.

Complexity

Examples

AC code of https://atcoder.jp/contests/practice2/tasks/practice2_g

include atcoder/header import atcoder/scc as scc_lib let n, m = nextInt() var g = init_scc_graph(n) for i in 0..<m: let u, v = nextInt() g.add_edge(u, v) var scc = g.scc() echo scc.len for v in scc: echo v.len, " ", v.join(" ")