# Strongly connected components in the graph

Problem:
You are given an unweighted directed graph of 'V' vertices and 'E' edges. Your task is to print strongly connected components (SCCs) present in the graph.

Input format:
You are given 'n' which is no. of vertices in the graph(0-based indexed)
'edges' 2d array of size m*2, where m is no. of edges and 2 is two vertices between which the edge exists. That is `edges[i]---->edges[i]` there is an edge between node `0` and `1`.

```TC: topo sort = O(N+E) + transpose of the graph = O(N+E) + dfs on topo sort with transpose graph = O(N+E) ```

``````import java.util.*;
public class Solution {

public static List<List<Integer>> stronglyConnectedComponents(int n, int[][] edges) {
List<List<Integer>> list = new ArrayList<>();
// we identify which are the strogly conected component,
// strongly connected components are the components where all the
//are reachable by every other node in the component.
//steps to solve this using kosaraju's SCC
//1. find toposort of the graph.
//2. transpose the graph(change direction of the edges)
//3. do dfs on the toposort with the transpose graph.
for(int i =0;i<n;i++) {
}
for(int ed [] : edges) {
}

int visited[] = new int[n];
Stack<Integer> stack = new Stack<>();
for(int i =0;i<n;i++){
if(visited[i]==0){
}
}
//now stack has topo sorted nodes in it.
Arrays.fill(visited,0);
while(!stack.isEmpty()){
int node   = stack.pop();
if(visited[node] ==0){

ArrayList<Integer> connComp = new ArrayList<>();
}
}
return list;
}
public static void dfsOnTransposeGraph(int node, int[] visited,
visited[node] = 1;
if(visited[it]==0) {
}
}
}
public static void dfs(int node, int[] visited, Stack<Integer> stack,
visited[node] = 1;
}
stack.push(node);
}
}
`````` 