def matrix_to_listlist(weight):
    """transforms a squared weight matrix in a adjacency table of type listlist
    encoding the directed graph corresponding to the entries of the matrix
    different from None

    :param weight: squared weight matrix, weight[u][v] != None iff arc (u,v) exists
    :complexity: linear
    :returns: the unweighted directed graph in the listlist representation,
                       listlist[u] contains all v for which arc (u,v) exists.
    """
    graph = [[] for _ in range(len(weight))]
    for u in range(len(graph)):
        for v in range(len(graph)):
            if weight[u][v] != None:
                graph[u].append(v)
    return graph
transforms a squared weight matrix in a adjacency table of type listlist
    encoding the directed graph corresponding to the entries of the matrix
    different from None

    :param weight: squared weight matrix, weight[u][v] != None iff arc (u,v) exists
    :complexity: linear
    :returns: the unweighted directed graph in the listlist representation,
                       listlist[u] contains all v for which arc (u,v) exists.