Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Second solution in Clear category for City's Happiness by juestr
def most_crucial(net, users):
def get_happiness(nodes):
value = 0
while nodes:
active = {nodes.pop()}
partval = 0
while active:
current = active.pop()
partval += users[current]
neighbors = nodes & {node for edge in net if current in edge for node in edge}
active |= neighbors
nodes -= neighbors
value += partval * partval
return value
nodes = set(users.keys())
happiness = { down: users[down] + get_happiness(nodes - set(down,)) for down in nodes }
most_unhappy = min(happiness.values())
return [node for node, mood in happiness.items() if mood == most_unhappy]
Oct. 5, 2019