TheAlgorithms/C++ 1.0.0
All the algorithms implemented in C++
Loading...
Searching...
No Matches
Solution Class Reference
Collaboration diagram for Solution:
[legend]

Public Member Functions

std::vector< std::vector< int > > search_bridges (int n, const std::vector< std::vector< int > > &connections)
 

Private Member Functions

void dfs (int current_node, int parent)
 

Private Attributes

std::vector< std::vector< int > > graph
 
std::vector< int > in_time
 
std::vector< int > out_time
 
int timer = 0
 
std::vector< std::vector< int > > bridge
 
std::vector< bool > visited
 

Detailed Description

Definition at line 11 of file bridge_finding_with_tarjan_algorithm.cpp.

Member Function Documentation

◆ dfs()

void Solution::dfs ( int current_node,
int parent )
inlineprivate

Definition at line 17 of file bridge_finding_with_tarjan_algorithm.cpp.

17 {
18 visited.at(current_node) = true;
19 in_time[current_node] = out_time[current_node] = timer++;
20 for (auto& itr : graph[current_node]) {
21 if (itr == parent) {
22 continue;
23 }
24 if (!visited[itr]) {
25 dfs(itr, current_node);
26 if (out_time[itr] > in_time[current_node]) {
27 bridge.push_back({itr, current_node});
28 }
29 }
30 out_time[current_node] =
31 std::min(out_time[current_node], out_time[itr]);
32 }
33 }
Graph Algorithms.

◆ search_bridges()

std::vector< std::vector< int > > Solution::search_bridges ( int n,
const std::vector< std::vector< int > > & connections )
inline

Definition at line 36 of file bridge_finding_with_tarjan_algorithm.cpp.

37 {
38 timer = 0;
39 graph.resize(n);
40 in_time.assign(n, 0);
41 visited.assign(n, false);
42 out_time.assign(n, 0);
43 for (auto& itr : connections) {
44 graph.at(itr[0]).push_back(itr[1]);
45 graph.at(itr[1]).push_back(itr[0]);
46 }
47 dfs(0, -1);
48 return bridge;
49 }

Member Data Documentation

◆ bridge

std::vector<std::vector<int> > Solution::bridge
private

Definition at line 15 of file bridge_finding_with_tarjan_algorithm.cpp.

◆ graph

std::vector<std::vector<int> > Solution::graph
private

Definition at line 12 of file bridge_finding_with_tarjan_algorithm.cpp.

◆ in_time

std::vector<int> Solution::in_time
private

Definition at line 13 of file bridge_finding_with_tarjan_algorithm.cpp.

◆ out_time

std::vector<int> Solution::out_time
private

Definition at line 13 of file bridge_finding_with_tarjan_algorithm.cpp.

◆ timer

int Solution::timer = 0
private

Definition at line 14 of file bridge_finding_with_tarjan_algorithm.cpp.

◆ visited

std::vector<bool> Solution::visited
private

Definition at line 16 of file bridge_finding_with_tarjan_algorithm.cpp.


The documentation for this class was generated from the following file: