def dancing_links(size_universe, sets):
    """Exact set cover by the dancing links algorithm

    :param size_universe: universe = {0, 1, ..., size_universe - 1}
    :param sets: list of sets
    :returns: list of set indices partitioning the universe, or None
    :complexity: huge
    """
    header = Cell(None, None, 0, None)  # building the cell structure
    col = []
    for j in range(size_universe):
        col.append(Cell(header, None, 0, None))
    for i in range(len(sets)):
        row = None
        for j in sets[i]:
            col[j].S += 1               # one more entry in this column
            row = Cell(row, col[j], i, col[j])
    sol = []
    if solve(header, sol):
        return sol
    else:
        return None
def dancing_links ( size_universe , sets ) : header = Cell ( None , None , 0 , None ) col = [ ] for j in range ( size_universe ) : col . append ( Cell ( header , None , 0 , None ) ) for i in range ( len ( sets ) ) : row = None for j in sets [ i ] : col [ j ] . S += 1 row = Cell ( row , col [ j ] , i , col [ j ] ) sol = [ ] if solve ( header , sol ) : return sol else : return None
Exact set cover by the dancing links algorithm

    :param size_universe: universe = {0, 1, ..., size_universe - 1}
    :param sets: list of sets
    :returns: list of set indices partitioning the universe, or None
    :complexity: huge