Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
use set object solution in Clear category for Node Disconnected Users by kurosawa4434
from collections import defaultdict
def disconnected_users(net, users, source, crushes):
all_users = sum(u for u in users.values())
if source in crushes:
return all_users
net_dic = defaultdict(set)
for n1, n2 in net:
if not set(crushes) & {n1, n2}:
net_dic[n1] |= {n2}
net_dic[n2] |= {n1}
next_nodes = set(net_dic[source])
live_nodes = next_nodes | {source}
while next_nodes:
search_nodes = next_nodes
next_nodes = set()
for sn in search_nodes:
next_nodes |= set(net_dic[sn])
live_nodes |= next_nodes
next_nodes -= live_nodes
return all_users - sum(users[n] for n in live_nodes)
April 28, 2017
Comments: