Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
15-liner: clean classic solution in Clear category for Network Attack by przemyslaw.daniel
from heapq import heapify, heappush, heappop
def capture(data):
out, stack, visited = 0, [(0, 0)], set()
heapify(stack)
while stack:
time, node = heappop(stack)
if node in visited:
continue
out, visited = max(out, time), visited | {node}
for i in range(len(data)):
if data[node][i] != 0:
heappush(stack, (time+data[i][i], i))
return out
Dec. 4, 2016
Comments: