Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
is heapq 3rd party? solution in Clear category for Network Attack by maybe
def capture(matrix):
"""sort of dijkstra algorithm with priority queue,
entry is tuple
(absolute time of completion of capure, node number)
note: there is no precondition that every computer is reachable
"""
from heapq import heappush, heappop
cleanset=set(range(1,len(matrix))) # not attacked yet
hq = []
heappush(hq,(0,0))
while hq:
now,badnode = heappop(hq)
for node in list(cleanset):
if matrix[badnode][node]: # node is connected to badnode
heappush(hq,(now+matrix[node][node], node))
cleanset.discard(node)
return now
Dec. 27, 2019