File tree Expand file tree Collapse file tree 2 files changed +9
-5
lines changed
Expand file tree Collapse file tree 2 files changed +9
-5
lines changed Original file line number Diff line number Diff line change @@ -69,7 +69,7 @@ class TarjanConnectivityAlgo {
6969 if (!processed[u]) {
7070 lowest[v] = std::min (lowest[v], num[u]);
7171 } // u not processed
72- } // u has been visited
72+ } // u has been visited
7373 }
7474
7575 // Now v has been processed
Original file line number Diff line number Diff line change @@ -26,8 +26,11 @@ template <typename WeightType = double> class NetworkOperations {
2626 std::optional<std::vector<size_t >> path_from_dfs (size_t s, size_t v) {
2727 std::vector<size_t > path{}; // Path from s to v
2828 reset_variables_counters (); // Reset marked and depth
29+ // There is no extra condition we want to put on the DFS, so make it always
30+ // return true
31+ auto condition = [this ]() { return true ; };
2932 // DFS starting from the source
30- dfs (s);
33+ dfs (s, condition );
3134 // Get one path if it exists
3235 return path_to_vertex (s, v);
3336 }
@@ -62,12 +65,13 @@ template <typename WeightType = double> class NetworkOperations {
6265 // (given by the index in this vector)
6366
6467 // Depth-first search from vertex v
65- void dfs (size_t v) {
68+ // Condition allows you to add some additional condition for applying the DFS
69+ template <typename Callback> void dfs (size_t v, Callback condition) {
6670 marked[v] = true ;
6771 for (size_t w : network.get_neighbours (v)) {
68- if (!marked[w]) {
72+ if (!marked[w] && condition () ) {
6973 edge_to_vertex[w] = v;
70- dfs (w);
74+ dfs (w, condition );
7175 }
7276 }
7377 }
You can’t perform that action at this time.
0 commit comments