Env: Python3Отправка приведенной ниже реализации привела к ошибке: Ошибка сегментации (SIGSEGV)
- Увеличение предела рекурсии до 1_000_000 не сработало li>
Реализация:def perform_dfs(self, source, adj, visited: set, dfs_order: list):
"""Recursively traverses the graph from the given source (vertex)
@param source: vertex (starting from 0)
@param adj: adjacency list of the graph; each vertex (as the index) mapped to its list of connected nodes
@param visited: a set to keep track of the visited nodes
"""
# BASE CASE:
if source in visited:
return dfs_order
# MAIN LOGIC:
visited.add(source)
dfs_order.append(source)
for adj_node in adj[source]:
self.perform_dfs(adj_node, adj, visited, dfs_order)
# return
return dfs_order
Подробнее здесь: https://stackoverflow.com/questions/790 ... lt-sigsegv