def is_cyclic(graph, cur_vertex, parent, visited) -> bool:
    """
    Detect cycle in an undirected graph using DFS.
    """
    visited.add(cur_vertex)

    for neighbor, connected in enumerate(graph[cur_vertex]):
        if connected and neighbor != parent:
            if neighbor in visited:
                return True
            else:
                has_cycle = is_cyclic(graph, neighbor, cur_vertex, visited)
                if has_cycle:
                    return True

    return False