8000 Merge pull request #1330 from chubakueno/chubakueno-patch-1 · cp-algorithms/cp-algorithms@7c2466d · GitHub
[go: up one dir, main page]

Skip to content

Commit 7c2466d

Browse files
authored
Merge pull request #1330 from chubakueno/chubakueno-patch-1
Remove components sort, Kosaraju should be O(n)
2 parents d9288f0 + 5689b63 commit 7c2466d

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

src/graph/strongly-connected-components.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ void strongly_connected_components(vector<vector<int>> const& adj,
119119
if (!visited[v]) {
120120
std::vector<int> component;
121121
dfs(v, adj_rev, component);
122-
sort(component.begin(), component.end());
123122
components.push_back(component);
124123
int root = component.front();
125124
for (auto u : component)
@@ -139,7 +138,7 @@ The function `dfs` implements depth first search. It takes as input an adjacency
139138
140139
Note that we use the function `dfs` both in the first and second step of the algorithm. In the first step, we pass in the adjacency list of $G$, and during consecutive calls to `dfs`, we keep passing in the same 'output vector' `order`, so that eventually we obtain a list of vertices in increasing order of exit times. In the second step, we pass in the adjacency list of $G^T$, and in each call, we pass in an empty 'output vector' `component`, which will give us one strongly connected component at a time.
141140
142-
When building the adjacency list of the condensation graph, we select the *root* of each component as the first vertex in its sorted list of vertices (this is an arbitrary choice). This root vertex represents its entire SCC. For each vertex `v`, the value `roots[v]` indicates the root vertex of the SCC which `v` belongs to.
141+
When building the adjacency list of the condensation graph, we select the *root* of each component as the first vertex in its list of vertices (this is an arbitrary choice). This root vertex represents its entire SCC. For each vertex `v`, the value `roots[v]` indicates the root vertex of the SCC which `v` belongs to.
143142
144143
Our condensation graph is now given by the vertices `components` (one strongly connected component corresponds to one vertex in the condensation graph), and the adjacency list is given by `adj_cond`, using only the root vertices of the strongly connected components. Notice that we generate one edge from $C$ to $C'$ in $G^\text{SCC}$ for each edge from some $a\in C$ to some $b\in C'$ in $G$ (if $C\neq C'$). This implies that in our implementation, we can have multiple edges between two components in the condensation graph.
145144

0 commit comments

Comments
 (0)
0