출처 : 위키피디아
def DFS(graph, start_node):
visited = []
stack = [start_node]
while stack:
n = stack.pop()
if n not in visited:
visited.append(n)
stack += graph[n] - set(visited)
return visited
def DFS(graph, start, visited=[]):
visited.append(start)
for node in graph[start]:
if node not in visited:
DFS(graph, node, visited)
return visited```