[Strong connectivity] The strongly connected template is Tarjan, and the connected template is tarjan.
I think it is much simpler than double-connected Tarjan. The idea and the dual-connected component are in the same pattern.
# Include <cstdio> # include <cstring> # include <cstdlib> # include <stack> using namespace std; const int N = 1e5; int dfn [N], scc_id [N]; int deep, scc_cnt; stack <int> s; int dfs (int u) {int lowu = dfn [u] = ++ deep; s. push (u); for (int I = head [u]; ~ I; I = e [I]. next) {int v = e [I]. v; if (! Dfn [v]) {int lowv = dfs (v); lowu = min (lowu, lowv);} else if (! Scc_id [v]) {// The untagged ancestor lowu = min (lowu, dfn [v]) connected to the stack;} // use the vertex in the current scc to update} if (lowu = dfn [u]) {// only the first detected vertex meets this condition scc_cnt ++; while (1) {int x = s. top (); s. pop (); scc_id [x] = scc_cnt; if (x = u) break;} return lowu;} void tarjan () {for (int I = 0; I <n; I ++) {dfn [I] = scc_id [I] = 0;} deep = scc_cnt = 0; for (int I = 0; I <n; I ++) {if (! Dfn [I]) dfs (I) ;}int main () {return 0 ;}