Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
sets solution in Clear category for New Cities by l.szyman10
def subnetworks(net, crushes):
nodes, subnets = set(), []
net = [set(i) - set(crushes) for i in net]
nodes = set.union(*net)
for node in nodes:
network = {node}
for _ in net:
for connection in net:
if connection & network:
network |= connection
if network not in subnets:
subnets.append(network)
return len(subnets)
Oct. 27, 2020
Comments: