From 5da2760d3fba77d88a98c0ad3e61bb13ad639777 Mon Sep 17 00:00:00 2001 From: Anirban Chetia Date: Mon, 18 Nov 2019 20:16:58 +0530 Subject: [PATCH 1/4] Kosaraju Algorithm for SCCs. --- Graph/Kosaraju.cpp | 103 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 Graph/Kosaraju.cpp diff --git a/Graph/Kosaraju.cpp b/Graph/Kosaraju.cpp new file mode 100644 index 000000000..a9131faa8 --- /dev/null +++ b/Graph/Kosaraju.cpp @@ -0,0 +1,103 @@ +/* Implementation of Kosaraju's Algorithm to find out the strongly connected components (SCCs) in a graph. + Author:Anirban166 +*/ + +#include +#include + +using namespace std; + +void print(vector a[],int V) +{ + for(int i=0;i"; + for(int j=0;j &st,bool vis[],vector adj[]) +{ + vis[v]=true; + for(auto i=adj[v].begin();i!=adj[v].end();i++) + { + if(vis[*i]==false) + calculate_time(*i,st,vis,adj); + } + st.push(v); +} +void dfs(int v,bool vis[],vector grev[]) +{ + vis[v]=true; + // cout< adj[]) +{ + // print(adj,V); + bool vis[V]={}; + stack st; + for(int v=0;v