Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for New Cities by Tinus_Trotyl
def subnetworks(net, crushes):
base, subs = dict(), set()
for node in net:
for a, b in (0, 1), (1, 0):
if not node[a] in crushes:
connect = [] if node[b] in crushes else [node[b]]
base[node[a]] = base[node[a]] + connect if node[a] in base else connect
for node in list(base):
if not (node in subs or any(i in subs for i in base[node])): subs |= {node}
return len(subs)
Aug. 22, 2017
Comments: