22 (1)
22 (1)
#include <vector>
#include <stack>
using namespace std;
class Graph {
private:
int V; // Number of vertices
vector<vector<int>> adj; // Adjacency list
// Check if the subtree rooted at v has a connection back to one of the ancestors
of
low[u] = min(low[u], low[v]);
// (2) If u is not root and low value of one of its child is more than discovery
value of
if (disc[u]>1&&low[v]>=disc[u]) {
articulation[u] = true;
vector<int> temp;
while (st.top() != make_pair(u, v)) {
temp.push_back(st.top().first);
temp.push_back(st.top().second);
st.pop();
}
temp.push_back(st.top().first);
temp.push_back(st.top().second);
st.pop();
bcc.push_back(temp);
}
} else if (v != st.top().first && disc[v] < low[u]) {
low[u] = disc[v];
st.push({u, v});
}
}
}
public:
Graph(int vertices) : V(vertices) {
adj.resize(V);
}
return bcc;
}
};
int main() {
// Create a graph given in the example
Graph g(12);
g.addEdge(0, 1);
g.addEdge(1, 2);
g.addEdge(1, 3);
g.addEdge(2, 3);
g.addEdge(2, 4);
g.addEdge(3, 5);
g.addEdge(4, 5);
g.addEdge(4, 6);
g.addEdge(5, 7);
g.addEdge(6, 7);
g.addEdge(7, 8);
g.addEdge(8, 9);
g.addEdge(8, 10);
g.addEdge(9, 10);
g.addEdge(9, 11);
g.addEdge(10, 11);
return 0;
}