public static void main(String args[]) {
        Graph<Integer> graph = new Graph<>(true);
        graph.addEdge(1,2);
        graph.addEdge(2,3);
        graph.addEdge(3,1);
        graph.addEdge(3,4);
        graph.addEdge(4,5);
        graph.addEdge(5,6);
        graph.addEdge(6,4);
        graph.addEdge(7,6);
        graph.addEdge(7,8);
        graph.addEdge(8,7);

        TarjanStronglyConnectedComponent tarjanStronglyConnectedComponent = new TarjanStronglyConnectedComponent();
        List<Set<Vertex<Integer>>> result = tarjanStronglyConnectedComponent.scc(graph);

        result.forEach(scc -> {
            scc.forEach(vertex -> System.out.print(vertex + " "));
            System.out.println();
        });

    }
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