Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Node Disconnected Users by tokiojapan55
def disconnected_users(net, users, source, crushes):
alone = set(users.keys())
alive = [n for n in net if n[0] not in crushes and n[1] not in crushes]
stack = [(source,)]
if source not in crushes:
alone -= {source}
while stack:
path = stack.pop()
for n in alive:
if path[-1] in n:
city = n[0] if path[-1]==n[1] else n[1]
if city not in path:
alone -= {city}
stack.append(path + (city,))
return sum([users[city] for city in alone])
Aug. 30, 2022