mirror of
https://hub.njuu.cf/TheAlgorithms/C-Plus-Plus.git
synced 2023-10-11 13:05:55 +08:00
fix: linter warnings for bridge finding algorithm. (#991)
* Fix linter warnings for bridge finding algorithm. * Comment main function.
This commit is contained in:
parent
62562abce3
commit
24653d9194
@ -7,15 +7,13 @@
|
||||
#include <algorithm> // for min & max
|
||||
#include <iostream> // for cout
|
||||
#include <vector> // for std::vector
|
||||
using std::cout;
|
||||
using std::min;
|
||||
using std::vector;
|
||||
|
||||
class Solution {
|
||||
vector<vector<int>> graph;
|
||||
vector<int> in_time, out_time;
|
||||
int timer;
|
||||
vector<vector<int>> bridge;
|
||||
vector<bool> visited;
|
||||
std::vector<std::vector<int>> graph;
|
||||
std::vector<int> in_time, out_time;
|
||||
int timer = 0;
|
||||
std::vector<std::vector<int>> bridge;
|
||||
std::vector<bool> 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<vector<int>> search_bridges(int n,
|
||||
const vector<vector<int>>& connections) {
|
||||
std::vector<std::vector<int>> search_bridges(
|
||||
int n,
|
||||
const std::vector<std::vector<int>>& 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<vector<int>> node;
|
||||
std::vector<std::vector<int>> 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<vector<int>> bridges = s1.search_bridges(number_of_node, node);
|
||||
cout << bridges.size() << " bridges found!\n";
|
||||
std::vector<std::vector<int>> 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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user