Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

I'm not sure if the following code is any faster, but it's purely in Sage without using any additional modules:

def remove_cc(G,S):
    H = G.copy()
    H.delete_vertices(S)
    return H.connected_components_number()

def toughness(G):
    return min(len(S)/c for S in Subsets(G.vertices()) if (c:=remove_cc(G,S))>=2)

print( toughness(graphs.CycleGraph(20)) )