diff --git a/graph/bridge_finding_with_tarjan_algorithm.cpp b/graph/bridge_finding_with_tarjan_algorithm.cpp index eec176af5..a9f76c033 100644 --- a/graph/bridge_finding_with_tarjan_algorithm.cpp +++ b/graph/bridge_finding_with_tarjan_algorithm.cpp @@ -7,15 +7,13 @@ #include // for min & max #include // for cout #include // for std::vector -using std::cout; -using std::min; -using std::vector; + class Solution { - vector> graph; - vector in_time, out_time; - int timer; - vector> bridge; - vector visited; + std::vector> graph; + std::vector in_time, out_time; + int timer = 0; + std::vector> bridge; + std::vector visited; void dfs(int current_node, int parent) { visited.at(current_node) = true; in_time[current_node] = out_time[current_node] = timer++; @@ -29,13 +27,14 @@ class Solution { bridge.push_back({itr, current_node}); } } - out_time[current_node] = min(out_time[current_node], out_time[itr]); + out_time[current_node] = std::min(out_time[current_node], out_time[itr]); } } public: - vector> search_bridges(int n, - const vector>& connections) { + std::vector> search_bridges( + int n, + const std::vector>& connections) { timer = 0; graph.resize(n); in_time.assign(n, 0); @@ -49,10 +48,14 @@ class Solution { return bridge; } }; -int main(void) { + +/** + * Main function + */ +int main() { Solution s1; int number_of_node = 5; - vector> node; + std::vector> node; node.push_back({0, 1}); node.push_back({1, 3}); node.push_back({1, 2}); @@ -70,10 +73,10 @@ int main(void) { * I assumed that the graph is bi-directional and connected. * */ - vector> bridges = s1.search_bridges(number_of_node, node); - cout << bridges.size() << " bridges found!\n"; + std::vector> bridges = s1.search_bridges(number_of_node, node); + std::cout << bridges.size() << " bridges found!\n"; for (auto& itr : bridges) { - cout << itr[0] << " --> " << itr[1] << '\n'; + std::cout << itr[0] << " --> " << itr[1] << '\n'; } return 0; }