|
|
|
|
|
by almostgotcaught
295 days ago
|
|
This is already the standard stack based DFS? def dfs(graph, source):
n = len(graph)
visited = set()
stack = [source]
while stack:
node = stack.pop()
if node in visited:
continue
visited.add(node)
for nbr in graph[node]:
stack.append(nbr)
So I don't know what all the confusion is about... |
|