Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
11-liner: just another easy solution solution in Clear category for Node Disconnected Users by przemyslaw.daniel
def subnetworks(net, crushes):
result = {x: {x} for x in sum(net, []) if x not in crushes}
for a, b in net*len(net):
if set(crushes) & {a, b}: continue
result[a] |= result[b] | {a, b}
result[b] |= result[a] | {a, b}
return result
def disconnected_users(net, users, source, crushes):
sum_all, subs = sum(users.values()), subnetworks(net, crushes)
return sum_all - sum([users[x] for x in subs.get(source, [])])
Oct. 25, 2017