Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
repeated BFS solution in Clear category for New Cities by juestr
def subnetworks(net, crushes):
nodes = ({n for n, _ in net} | {n for _, n in net}) - set(crushes)
partitions = 0
while len(nodes):
partitions += 1
front = {nodes.pop()}
while len(front):
front = {(a if b in front else b) for a, b in net if {a, b} & front} & nodes
nodes -= front
return partitions
April 21, 2019