SCC

It calculates the strongly connected components of directed graphs.

Constructor

scc_graph graph(int n)

It creates a directed graph with nn vertices and 00 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/scc>
#include <cstdio>
using namespace std;
using namespace atcoder;
int main() {
int n, m;
scanf("%d %d", &n, &m);
scc_graph g(n);
for (int i = 0; i < m; i++) {
int u, v;
scanf("%d %d", &u, &v);
g.add_edge(u, v);
}
auto scc = g.scc();
printf("%d\n", int(scc.size()));
for (auto v : scc) {
printf("%d", int(v.size()));
for (int x : v) {
printf(" %d", x);
}
printf("\n");
}
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX