Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Cycle in Directed Graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
sys.setrecursionlimit(1000000)
from collections import defaultdict
class Graph:
@staticmethod
def __init__(self,v):
self.d=defaultdict(list)
self.V=v
@staticmethod
def addedge(self,u,v):
self.d[u].append(v)
@staticmethod
def cycleditact(self,s,visited,restack):
visited[s]=True
restack[s]=True
Expand All @@ -20,6 +23,7 @@ def cycleditact(self,s,visited,restack):
return True
restack[s]=False
return False
@staticmethod
def cycle(self):
visited=[False for i in range(self.V+1)]
restack=[False for i in range(self.V+1)]
Expand All @@ -32,6 +36,7 @@ class Solution:
# @param A : integer
# @param B : list of list of integers
# @return an integer
@staticmethod
def solve(self, A, B):
g=Graph(A)
for p in B:
Expand Down