@@ -0,0 +1,2490 @@
+# Python implementation of Kosaraju's algorithm to print all SCCs%0A %0Afrom collections import defaultdict%0A  %0A#This class represents a directed graph using adjacency list representation%0Aclass Graph:%0A  %0A    def __init__(self,vertices):%0A        self.V= vertices #No. of vertices%0A        self.graph = defaultdict(list) # default dictionary to store graph%0A  %0A    # function to add an edge to graph%0A    def addEdge(self,u,v):%0A        self.graph%5Bu%5D.append(v)%0A  %0A    # A function used by DFS%0A    def DFSUtil(self,v,visited):%0A        # Mark the current node as visited and print it%0A        visited%5Bv%5D= True%0A        print v,%0A        #Recur for all the vertices adjacent to this vertex%0A        for i in self.graph%5Bv%5D:%0A            if visited%5Bi%5D==False:%0A                self.DFSUtil(i,visited)%0A %0A %0A    def fillOrder(self,v,visited, stack):%0A        # Mark the current node as visited %0A        visited%5Bv%5D= True%0A        #Recur for all the vertices adjacent to this vertex%0A        for i in self.graph%5Bv%5D:%0A            if visited%5Bi%5D==False:%0A                self.fillOrder(i, visited, stack)%0A        stack = stack.append(v)%0A     %0A %0A    # Function that returns reverse (or transpose) of this graph%0A    def getTranspose(self):%0A        g = Graph(self.V)%0A %0A        # Recur for all the vertices adjacent to this vertex%0A        for i in self.graph:%0A            for j in self.graph%5Bi%5D:%0A                g.addEdge(j,i)%0A        return g%0A %0A  %0A  %0A    # The main function that finds and prints all strongly%0A    # connected components%0A    def printSCCs(self):%0A         %0A        stack = %5B%5D%0A        # Mark all the vertices as not visited (For first DFS)%0A        visited =%5BFalse%5D*(self.V)%0A        # Fill vertices in stack according to their finishing%0A        # times%0A        for i in range(self.V):%0A            if visited%5Bi%5D==False:%0A                self.fillOrder(i, visited, stack)%0A %0A        # Create a reversed graph%0A        gr = self.getTranspose()%0A         %0A        # Mark all the vertices as not visited (For second DFS)%0A        visited =%5BFalse%5D*(self.V)%0A %0A        # Now process all vertices in order defined by Stack%0A        while stack:%0A            i = stack.pop()%0A            if visited%5Bi%5D==False:%0A                gr.DFSUtil(i, visited)%0A                print%22%22%0A  %0A# Create a graph given in the above diagram%0Ag = Graph(5)%0Ag.addEdge(1, 0)%0Ag.addEdge(0, 2)%0Ag.addEdge(2, 1)%0Ag.addEdge(0, 3)%0Ag.addEdge(3, 4)%0A %0A  %0Aprint (%22Following are strongly connected components %22 +%0A                           %22in given graph%22)%0Ag.printSCCs()%0A

Create kosaraju_algo.py