public List<Set<Vertex<Integer>>> scc(Graph<Integer> graph) {

        //keeps the time when every vertex is visited
        time = 0;
        //keeps map of vertex to time it was visited
        visitedTime = new HashMap<>();

        //keeps map of vertex and time of first vertex visited in current DFS
        lowTime = new HashMap<>();

        //tells if a vertex is in stack or not
        onStack = new HashSet<>();

        //stack of visited vertices
        stack = new LinkedList<>();

        //tells if vertex has ever been visited or not. This is for DFS purpose.
        visited = new HashSet<>();

        //stores the strongly connected components result;
        result = new ArrayList<>();

        //start from any vertex in the graph.
        for (Vertex<Integer> vertex : graph.getAllVertex()) {
            if(visited.contains(vertex)) {
                continue;
            }
            sccUtil(vertex);
        }

        return result;
    }
Date 08/16/2015
@author Tushar Roy

Find strongly connected components of directed graph.

Time complexity is O(E + V)
Space complexity  is O(V)

Reference - https://en.wikipedia.org/wiki/Tarjan%27s_strongly_connected_components_algorithm
src/com/interview/graph/TarjanStronglyConnectedComponent.java