1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Python] GeeksForGeeks Online Judge | Python3 | Recursion: Segmentation Fault (SIGSEGV)

Discussão em 'Python' iniciado por Stack, Outubro 8, 2024.

  1. Stack

    Stack Membro Participativo

    Question Link: https://www.geeksforgeeks.org/problems/depth-first-traversal-for-a-graph/1

    Env: Python3

    Submission of the below implementation resulting in an error: Segmentation Fault (SIGSEGV)

    • Increasing the recursion limit to 1_000_000 did not work

    Problem Constraint: 1 ≤ V, E ≤ (10**4)

    Implementation:

    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

    Continue reading...

Compartilhe esta Página