Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for How to Find Friends by ssk8
def check_connection(network, first, second):
change, groups = True, [set(s.split('-')) for s in network]
while change:
change = False
for group1 in groups:
for group2 in groups:
if len(group1 & group2) == 1:
groups = [s for s in groups + [group1.union(group2)] if s not in (group1, group2)]
change = True
break
if change: break
return any([{first, second} <= group for group in groups])
July 24, 2018
Comments: