Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
While u have any friends solution in Clear category for How to Find Friends by MrPod
def check_connection(network, first, second):
d = {}
for net in network:
a, b = net.split('-')
d[a] = d.get(a, set()) | {b}
d[b] = d.get(b, set()) | {a}
visited = set()
to_visit = set()
guy = first
while True:
if guy not in visited:
visited.add(guy)
to_visit |= set(d[guy])
if second in to_visit:
return True
if to_visit:
guy = to_visit.pop()
else:
return False
Sept. 7, 2019
Comments: