Code 6
Code 6
h>
using namespace std;
class Solution {
private:
// First DFS to fill the stack in order of finishing times (post-order)
void dfs(int node, vector<int> &vis, vector<int> adj[],
stack<int> &st) {
vis[node] = 1;
for (auto it : adj[node]) {
if (!vis[it]) {
dfs(it, vis, adj, st); // explore neighbor
}
}
st.push(node); // all descendants explored, push to stack
}
public:
// Function to find number of strongly connected components in the graph.
int kosaraju(int V, vector<int> adj[]) {
vector<int> vis(V, 0); // visited array for original graph
stack<int> st; // stack to store vertices by finish time
vector<int> adj[n];
Solution obj;
int ans = obj.kosaraju(n, adj);
return 0;
}