def rearrange_adj_matrix(matrix, ordering):
    assert (matrix.ndim == 2)
    assert (matrix.shape[0] == matrix.shape[1])
    num_nodes = matrix.shape[0]
    assert (len(ordering) == num_nodes)
    matrix = matrix[ordering, :]
    matrix = matrix[:, ordering]
    return matrix
def rearrange_adj_matrix(matrix, ordering):
    assert (matrix.ndim == 2)
    assert (matrix.shape[0] == matrix.shape[1])
    num_nodes = matrix.shape[0]
    assert (len(ordering) == num_nodes)
    matrix = matrix[ordering, :]
    matrix = matrix[:, ordering]
    return matrix