def cost(dic, PhoneCost, EmailCost, OverbondCost):
    """Calculates the cost by summing over all connections in the dictionary dic.
       Note that this time only one of the vertices knows of the connection to
       avoid redundancy.
    """
    price = [OverbondCost, PhoneCost, EmailCost]
    result = 0.0
    for a in dic:   # iterating over all vertices in the clique
        for b in dic[a]: # iterating over all neighbours of the vertex a
            result += sum([x*y for x,y in zip(dic[a][b],price)])

    return result