void tarjanSCC(int u) {
    dfs_low[u] = dfs_num[u] = dfsNumberCounter++; // dfs_low[u] <= dfs_num[u]
    S.push_back(u); // stores u in a vector based on order of visitation
    visited[u] = 1;
    for (int j = 0; j < (int)AdjList[u].size(); j++) {
        ii v = AdjList[u][j];
        if (dfs_num[v.first] == 0)
            tarjanSCC(v.first);
        if (visited[v.first])
            dfs_low[u] = min(dfs_low[u], dfs_low[v.first]); }
    if (dfs_low[u] == dfs_num[u]) { // if this is a root (start) of an SCC
        scc.push_back(vi());
        while (1) {
            int v = S.back(); S.pop_back(); visited[v] = 0;
            scc.back().push_back(v);
            node_to_scc_num[v] = scc_num;
            if (u == v) break; }
        scc_num++;
    }
 }
Ejemplo n.º 2
0
	vi &get_array() { return P.back(); }