mirror of
https://github.com/TheAlgorithms/C-Plus-Plus.git
synced 2026-04-14 19:00:15 +08:00
formatting source-code for 153fb7b8a5
This commit is contained in:
@@ -10,28 +10,22 @@
|
||||
using std::cout;
|
||||
using std::min;
|
||||
using std::vector;
|
||||
class Solution
|
||||
{
|
||||
class Solution {
|
||||
vector<vector<int>> graph;
|
||||
vector<int> in_time, out_time;
|
||||
int timer;
|
||||
vector<vector<int>> bridge;
|
||||
vector<bool> visited;
|
||||
void dfs(int current_node, int parent)
|
||||
{
|
||||
void dfs(int current_node, int parent) {
|
||||
visited.at(current_node) = true;
|
||||
in_time[current_node] = out_time[current_node] = timer++;
|
||||
for (auto& itr : graph[current_node])
|
||||
{
|
||||
if (itr == parent)
|
||||
{
|
||||
for (auto& itr : graph[current_node]) {
|
||||
if (itr == parent) {
|
||||
continue;
|
||||
}
|
||||
if (!visited[itr])
|
||||
{
|
||||
if (!visited[itr]) {
|
||||
dfs(itr, current_node);
|
||||
if (out_time[itr] > in_time[current_node])
|
||||
{
|
||||
if (out_time[itr] > in_time[current_node]) {
|
||||
bridge.push_back({itr, current_node});
|
||||
}
|
||||
}
|
||||
@@ -41,15 +35,13 @@ class Solution
|
||||
|
||||
public:
|
||||
vector<vector<int>> search_bridges(int n,
|
||||
const vector<vector<int>>& connections)
|
||||
{
|
||||
const vector<vector<int>>& connections) {
|
||||
timer = 0;
|
||||
graph.resize(n);
|
||||
in_time.assign(n, 0);
|
||||
visited.assign(n, false);
|
||||
out_time.assign(n, 0);
|
||||
for (auto& itr : connections)
|
||||
{
|
||||
for (auto& itr : connections) {
|
||||
graph.at(itr[0]).push_back(itr[1]);
|
||||
graph.at(itr[1]).push_back(itr[0]);
|
||||
}
|
||||
@@ -57,8 +49,7 @@ class Solution
|
||||
return bridge;
|
||||
}
|
||||
};
|
||||
int main(void)
|
||||
{
|
||||
int main(void) {
|
||||
Solution s1;
|
||||
int number_of_node = 5;
|
||||
vector<vector<int>> node;
|
||||
@@ -81,8 +72,7 @@ int main(void)
|
||||
*/
|
||||
vector<vector<int>> bridges = s1.search_bridges(number_of_node, node);
|
||||
cout << bridges.size() << " bridges found!\n";
|
||||
for (auto& itr : bridges)
|
||||
{
|
||||
for (auto& itr : bridges) {
|
||||
cout << itr[0] << " --> " << itr[1] << '\n';
|
||||
}
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user