Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
simple BFS solution in Clear category for Node Disconnected Users by juestr
from itertools import chain
flatten = chain.from_iterable
def disconnected_users(net, users, source, crushes):
goodnet = [path for path in net if set(path).isdisjoint(crushes)]
visited = set()
active = set((source,)) - set(crushes)
while True:
if not active:
break
visited |= active
active = { b for a, b in goodnet if a in active and b not in visited }
unreachable = set(flatten(net)) - visited
return sum(users[n] for n in unreachable)
April 27, 2019
Comments: