MCPcopy Create free account
hub / github.com/SuprDewd/CompetitiveProgramming / scc

Function scc

code/graph/scc.cpp:9–27  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7 if (!visited[v = adj[u][i]]) scc_dfs(adj, v);
8 order.push_back(u); }
9pair<union_find, vi> scc(const vvi &adj) {
10 int n = size(adj), u, v;
11 order.clear();
12 union_find uf(n); vi dag; vvi rev(n);
13 rep(i,0,n) rep(j,0,size(adj[i])) rev[adj[i][j]].push_back(i);
14 visited.resize(n);
15 fill(visited.begin(), visited.end(), false);
16 rep(i,0,n) if (!visited[i]) scc_dfs(rev, i);
17 fill(visited.begin(), visited.end(), false);
18 stack<int> S;
19 for (int i = n-1; i >= 0; i--) {
20 if (visited[order[i]]) continue;
21 S.push(order[i]), dag.push_back(order[i]);
22 while (!S.empty()) {
23 visited[u = S.top()] = true, S.pop();
24 uf.unite(u, order[i]);
25 rep(j,0,size(adj[u]))
26 if (!visited[v = adj[u][j]]) S.push(v); } }
27 return pair<union_find, vi>(uf, dag); }
28// vim: cc=60 ts=2 sts=2 sw=2:

Callers 12

test_1Function · 0.85
test_2Function · 0.85
test_3Function · 0.85
test_4Function · 0.85
test_5Function · 0.85
test_6Function · 0.85
test_7Function · 0.85
test_8Function · 0.85
test_9Function · 0.85
test_10Function · 0.85
test_11Function · 0.85
test_12Function · 0.85

Calls 8

scc_dfsFunction · 0.85
push_backMethod · 0.80
uniteMethod · 0.80
clearMethod · 0.45
pushMethod · 0.45
emptyMethod · 0.45
topMethod · 0.45
popMethod · 0.45

Tested by 12

test_1Function · 0.68
test_2Function · 0.68
test_3Function · 0.68
test_4Function · 0.68
test_5Function · 0.68
test_6Function · 0.68
test_7Function · 0.68
test_8Function · 0.68
test_9Function · 0.68
test_10Function · 0.68
test_11Function · 0.68
test_12Function · 0.68