Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Explore solution in Clear category for How to Find Friends by altarfinch
def check_connection(n, A, B):
visited = set()
toVisit = {A}
while toVisit:
current = toVisit.pop()
visited |= {current}
for l in n:
a,b = l.split('-')
if b == current: a,b = b,a
if a == current and b not in visited:
if b == B:
return True
toVisit |= {b}
return False
Feb. 9, 2015