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 tokiojapan55
def check_connection(network, first, second):
queue = [(first,)]
while queue:
path = queue.pop()
if path[-1]==second:
return True
for f,s in [n.split('-') for n in network]:
if f==path[-1] and s not in path:
queue.append(path+(s,))
if s==path[-1] and f not in path:
queue.append(path+(f,))
return False
June 15, 2020