Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
thanks to defaultdict I was able to link Nodes solution in Speedy category for Node Disconnected Users by Stensen
from collections import defaultdict
def disconnected_users(net, usrs, src, crushes):
G = defaultdict(list)
for fN, sN in net: G[fN].append(sN); G[sN].append(fN)
if src not in crushes:
reached, queue = {src}, [src]
while queue:
pop = queue.pop()
for N in G[pop]:
if N not in reached and N not in crushes:
reached.add(N); queue.insert(0, N)
return sum(N for n, N in usrs.items() if n not in reached)
else: return sum(usrs.values())
Oct. 10, 2020
Comments: